Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, For my Java Object Oriented Programming class, we are learning about polymorphism and abstract classes. I unfortunately had to miss one of the lectures

Hello,

For my Java Object Oriented Programming class, we are learning about polymorphism and abstract classes. I unfortunately had to miss one of the lectures so I am a bit confused on how to get this program going. Here's what needs to be done with the program and one of the pre-defined classes is attached to here. This will need to use polymorphism as well.

image text in transcribed

//Abstract class ParkingSpace

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();

}

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

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

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions