Question: 1. Define a class RegularParkingSpace , which is a subclass of ParkingSpace. Add a constructor which makes a regular parking space with a given space
1. Define a class RegularParkingSpace, which is a subclass of ParkingSpace. Add a constructor which makes a regular parking space with a given space number. Override the abstract method showSpaceType to show this is a Regular Parking Space.
2. Define a class HandicappedParkingSpace, which is a subclass of ParkingSpace. Add a constructor which makes a handicapped parking space with a given space number. Override the abstract method showSpaceType to show this is a Handicapped Parking Space.
3. Define a class ParkingLot. A parking lot generally has a number of parking spaces. (You are asked to use composition)
a). Add a default constructor which initializes a parking lot with 5 parking spaces. The first two spaces numbered 1000 and 1001 are handicapped parking spaces. The left three spaces numbered 1002, 1003 and 1004 are regular parking spaces.
b). Add a method that returns the number of parking spaces in the parking lot.
c). Add getters as needed.
4. Define a driver class TestParking. In its main method, declare and instantiate a parking lot using default constructor. Print the type of every parking space in this parking lot, such as
Parking space 1000: It is a handicapped parking space.
Your code MUST reflect the use of polymorphism.
*****
ParkingSpace Class
package parking_space;
abstract public class ParkingSpace {
private int spaceNum;
private boolean isEmpty;
public ParkingSpace(int spaceNum)
{
this.spaceNum = spaceNum;
}
public int getSpaceNum() {
return spaceNum;
}
public boolean isEmpty() {
return isEmpty;
}
public void setEmpty(boolean isEmpty) {
this.isEmpty = isEmpty;
}
//It is to show the type of the parking space.
//Subclasses will override it.
abstract public void showSpaceType();
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
