Homework

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

ParkingGarage

Prompt
The owner of a parking garage wants you to design a Java program that will track each car’s
location in the garage so that new cars will automatically know the closest open space and
pedestrians returning to their cars can access their car’s location and how to walk to it.

The ParkingGarage class has an Array of Vehicle objects. The implementation of the Vehicle
class is shown below:

public class Vehicle {


private String make;
private String model;
private String VIN; // Vehicle Identification Number. Unique to
every vehicle

public Vehicle(String make, String model, String VIN) {


this.make = make;
this.model = model;
this.VIN = VIN;
}

public String getVIN() {


return VIN;
}

// other methods left out that are not needed


}

The ParkingGarage is implemented as a 3D Array - an array of 2D arrays, with the outermost


array representing the floors, the middle arrays representing each row, and the innermost items
representing the spaces. A visual depiction of a hypothetical ParkingGarage with dimensions
[3][5][5] is shown below:
Some starter code for the ParkingGarage class is shown below. You will be writing the details
for the constructor (part a), the addVehicle method (part b), the removeVehicle method (part c),
and the getDirectionsToVehicle method (part d).

public class ParkingGarage {


private Vehicle[][][] garage;

public ParkingGarage(int numFloors, int numRows, int numSpaces) {


// missing code (part a)
}

// searches from the bottom floor and adds it to the first empty
spot found. Returns false if garage is full
public boolean addVehicle(Vehicle vehicle) {
// missing code (part b)
}

// returns false if vehicle is not in garage


public boolean removeVehicle(Vehicle vehicle) {
// missing code (part c)
}
/* Examples:
"Sorry. Vehicle is not in the garage."
"Take the elevator to floor 3. Walk to row 2. Car is in space
0."
"Take the elevator to floor 2. Stay in row 0. Car is in space
7."
"Stay on floor 0. Stay in row 0. Car is in space 2." */
public String getDirectionsToVehicle(Vehicle vehicle) {
// missing code (part d)
}
}

Student Response
To receive full credit for this assignment, complete each of the blue boxes below. Expand the
size of the boxes as needed.

Part a) ParkingGarage constructor

public ParkingGarage(int numFloors, int numRows, int numSpaces) {

Part b) addVehicle

public boolean addVehicle(Vehicle vehicle) {


}

Part c) removeVehicle

public boolean removeVehicle(Vehicle vehicle) {

Part d) getDirectionsToVehicle

public String getDirectionsToVehicle(Vehicle vehicle) {

You might also like