Question: Garage.java package unl.cse.parking; public class Garage { private final Vehicle stalls[]; public Garage(int capacity) { stalls = new Vehicle[capacity]; } /** * Parks the vehicle
![Garage.java package unl.cse.parking; public class Garage { private final Vehicle stalls[];](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f533ac7e3c9_58066f533ac04ada.jpg)
![public Garage(int capacity) { stalls = new Vehicle[capacity]; } /** * "Parks"](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f533ad3bd23_58066f533accf3d8.jpg)


Garage.java
package unl.cse.parking;
public class Garage {
private final Vehicle stalls[];
public Garage(int capacity) {
stalls = new Vehicle[capacity];
}
/**
* "Parks" the vehicle in a stall if one is available. Returns true if
* the vehicle was added successfully; false otherwise.
*/
public boolean addVehicle(Vehicle automobile) {
//TODO: implement this method
return false;
}
/**
* Remove the vehicle having the provided
* license plate number from the garage. The method returns
* the vehicle if it is found otherwise it returns null.
*/
public Vehicle removeVehicle(String license) {
//TODO: implement this method
return null;
}
/**
* Returns the maximum capacity of this Garage
*/
public int getCapacity() {
return this.stalls.length;
}
/**
* Returns the number of empty stalls in the garage--the number of open
* spots
* @return
*/
public int getNumFreeSpots() {
int freeSpots = 0;
for(int i=0; i if(stalls[i] == null) { freeSpots++; } } return freeSpots; } /** * Simulates the passing of a day by adding a day in the garage to each vehicle * in the garage. * @return */ public void addDay() { //TODO: implement this } public void addDay(int numDays) { //TODO: optionally implement this as well } /** * Displays the current "state" of the garage by printing out information about each * stall */ public void displayReport() { System.out.println("Stall License Type Days Total Fee"); for(int i=0; i if(stalls[i] == null) { System.out.println(String.format("%3d EMPTY", (i+1))); } else { //TODO: You will need to modify these arguments to display the report correctly System.out.println(String.format("%3d %-10s %-11s %3d $%5.2f", (i+1), stalls[i].getLicense(), "TODO-TYPE", -1, -1.0)); } } } } GarageStimulation.java package unl.cse.parking; public class GarageSimulation { public static void main(String[] args) { Garage safePark = new Garage(10); Vehicle herbie = new Vehicle("OFP 857"); safePark.addVehicle(herbie); safePark.addDay(); safePark.addDay(); safePark.addDay(); safePark.displayReport(); } } Vehicle.java package unl.cse.parking; public class Vehicle { private final String license; // The class constructor public Vehicle(String license) { this.license = license; } /** * The getter method granting public access to reading the * license plate number. Notice license does not have a * setter since it cannot be modified. */ public String getLicense() { return license; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
