Question: Hi, I am currently in a Java class and we are learning about polymorphism and abstract methods. I am working on a program, but I

Hi,

I am currently in a Java class and we are learning about polymorphism and abstract methods. I am working on a program, but I need help with the last two parts. I will attach the assignment guidelines and what I have so far. This needs to have polymorphism or else the assignment will be failed according to my instructor.

Thank You!

Assignment Guidelines:

Hi, I am currently in a Java class and we are learning

Code that I have done:

package parking_space;

abstract public class ParkingSpace {

// Instance Variables

private int spaceNum;

private boolean isEmpty;

// Alternate Constructor

public ParkingSpace(int spaceNum) {

this.spaceNum = spaceNum;

}

// Getter for spaceNum

public int getSpaceNum() {

return spaceNum;

}

public boolean isEmpty() {

return isEmpty;

}

// Stter for 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();

}//end of abstract class ParkingSpace

package parking_space;

public class RegularParkingSpace extends ParkingSpace {

//Alternate Constructor

public RegularParkingSpace(int spaceNum) {

super(spaceNum);

}

//Override Abstract Method

@Override

public void showSpaceType() {

System.out.println(" Parking Space " + getSpaceNum() + ": It is a Regular Parking Space");

}

}//end of class RegularParkingSpace

package parking_space;

public class HandicappedParkingSpace extends ParkingSpace {

//Alternate Constructor

public HandicappedParkingSpace(int spaceNum) {

super(spaceNum);

}

//Override Abstract Method

@Override

public void showSpaceType() {

System.out.println(" Parking Space " + getSpaceNum() + ": It is a Handicapped Parking Space");

}

}//end of class HandicappedParkingSpace

Create a Java project named CS235PA4. Right click "src" to import the jar file Parking (General->Archive File). You will find an abstract class called ParkingSpace is defined, which includes an abstract method showSpaceType to show the type of the parking 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) 4. a. Add a default constructor which initiae a prking 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. Add a method that returns the number of parking spaces in the parking lot. Add getters as needed. b. c. 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 5. "Parking space 10: It is a handicapped parking space." Your code MUST reflect the use of polymorphism. Otherwise, this assignment will be failed. Create a Jar file for your project and upload to PA4 on D2L. Wrong submission will result penalty

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!