subject

A parking garage consists of several levels with many parking spaces on each level. A garage management program keeps track of the number of cars parked in the garage and helps to find the location of a car with a given ID. Consider the following three Java classes used in this program. The class Car represents an individual car: public class Car // returns the id of this car public String getID) { /* implementation not shown */) // private data, constructors, and other methods not shown The class Parking Level represents one level of the garage: public class Parking Level // returns the number of parking spaces on this level public int numSpaces() { /* implementation not shown */ ) W returns the car parked in the space number spaceNum W or null if that space is empty public car getcar(int spaceNum) ( 7 implementation not shown * W returns the smallest space number of an available space or 11 -1 16 the level is full and there and no empty spaces public int findEmptySpace () / implementation not shown) 1/ marks space number spaceNum on this level as occupied W by car vi i v- null the space is marked as empty // precondition: space number spaceNum 18 empty public void setCar(int spaceNum, Car v) (7. implementation not shown * // private data, constructors, and other methods not shown A Parking Level object keeps track of the cars parked within its spaces as well as empty spaces. The parking spaces on each level are numbered by consecutive integers, starting from 0. The ParkingGarage class keeps track of all the levels in the garage. It keeps the information about the levels in an array of ParkingLevel objects. public class ParkingGarage private int totalCars; // total number of cars in this garage private ParkingLevelll levels; // each element corresponds to a level in the garage // returns true if there are no available spaces on any 1 level within the garage; otherwise, returns false public boolean is Full() { /* implementation not shown */) 1/ returns true if a car with a given ID is already parked somewhere in the garage; otherwise, returns false public boolean isCarAlreadyParked (String id) { / Implementation not shown */ } // if the garage is not full and no car with the same ID // as v's ID is in the garage yet, parks Car v into the // garage, updates the number of cars parked in the // garage, and returns true; otherwise, leaves the garage // unchanged and returns false public boolean parkCar (Car v) ( * TO BE IMPLEMENTED */ } private ParkingLevellevels; . W/ each element corresponds to a level in the garage // returns true if there are no available spaces on any // level within the garage; otherwise, returns false public boolean isFull) { /* implementation not shown */) V/ returns true if a car with a given ID is already parked W somewhere in the garage; otherwise, returns false public boolean isCarAlreadyParked (String id) { /* implementation not shown // if the garage is not full and no car with the same ID // as v's ID is in the garage yet, parks Car v into the // garage, updates the number of cars parked in the // garage, and returns true; otherwise, leaves the garage // unchanged and returns false public boolean parkCar (Car v) { /* TO BE IMPLEMENTED */ } // if a car with a given ID String id is found, removes // that car, updates the number of cars parked in the garage // and returns the found car; otherwise, leaves the garage // unchanged and returns null // precondition: id is not null and is a non-empty string public Car removeCar (String id) { /* implementation not shown */ } 77 private data, constructors, and other methods not shown. (QUESTION) Write the parkCar method of the ParkingGarage class. If the parking garage is not full and if the car is not already in the garage, then the car should be parked in an empty space, the number of cars in the garage should be updated. and the method should return true, indicating successful parking. Otherwise, the garage data should remain unchanged and the method should return false, indicating that the car was not parked. In writing parkCar, you may call any accessible methods in the car and ParkingLevel classes. Assume that these methods work as specified Complete method parkCar below. // if the garage is not full and no car with the same ID // as v's ID is in the garage yet, parks Car v into the // garage, updates the number of cars parked in the 1/ garage, and returns true; otherwise, leaves the garage // unchanged and returns false public boolean parkCar (Carv)

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 05:10, kellysimkin6196
Read the code below. what will the computer print if the input for year_variable is 1700? if year_variable == 1776: print("your answer is correct. the declaration of independence was signed in “year_variable”.") elif year_variable < 1776: compute_variable = 1776 - year_variable. print("add “compute_variable“ years to your answer for the correct answer.") elif year_variable > 1776: compute_variable = year_variable - 1776 print("subtract “compute_variable” years from your answer for the correct answer.")
Answers: 1
image
Computers and Technology, 22.06.2019 18:30, yayamcneal05
Which cultural aspect does this type of song best portray? a german polka dance
Answers: 1
image
Computers and Technology, 24.06.2019 01:30, jadaroyval
Write a program that asks the user to enter the name of an input file. if the file does not exist, the program should prompt the user to enter the file name again. if the user types quit in any uppercase/lowercase combinations, then the program should exit without any further output.
Answers: 3
image
Computers and Technology, 24.06.2019 03:00, paguy12
What is one potential problem associated with an organization purchasing new technology early in its lifecycle
Answers: 1
You know the right answer?
A parking garage consists of several levels with many parking spaces on each level. A garage managem...

Questions in other subjects:

Konu
Chemistry, 29.01.2021 20:20