Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 using the try-catch block for the methods described above. Use the array in the valet to throw an error message to the user about no spaces being available.
  • NoCarException.java: Create a new exception class using the try-catch block for the methods described above. Use the array in the valet to throw an error message to the user about no cars being available.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions