Question: Java Implement an application that represents a valet parking system which manages 10 parking spots. Create the following classes: Car.java : Create a class named

Java

Implement an application that represents a valet parking system which manages 10 parking spots. Create the following classes:

  • Car.java: Create a class named Car which has four instance variables for make, model, year and color with appropriate accessibility levels. Add getter and setter methods for each member variable. Add a default constructor and a constructor that expects values for each member variable. Also, override the toString() method of java.lang.Object with an appropriate description of a vehicle.
  • Valet.java: Implement a class that represents the parking spots reserved for valet parking using an array. Initially, all spots available. The class must have the following methods:
    • void park(Car car) throws NoSpaceAvailableException: This method parks the car in the next available spot. It essentially stores the Car object passed to it to the next free spot in the array. The first car is parked in spot 0, then next one in spot 1, etc. If no more spot is available, the method throws a NoSpaceAvailableException.
    • Car get(int spot) throws NoCarException: This method retrieves the car at the spot passed to it. In other words, it simply returns the car stored at the specified index in the array. If the index is out of bounds or if theres no car located at the spot specified, it throws a NoCarException.
    • Car leave(int spot) throws NoCarException: This method removes one car at the spot that is passed to it. The return type Car means that this function must return a car object. In this case, it is the car that is removed from the array. If the spot index is out of bounds or if theres no car located at the spot specified, it throws a NoCarException.
  • NoSpaceAvailableException.java: Create a new exception class which is used in the methods describe above.
  • NoCarException.java: Create a new exception class which is used in the methods describe above.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!