Question: Task 1 : Implement Class Structure from the Diagram Implement the classes from the class diagram. o Create base and subclasses as shown in the

Task 1: Implement Class Structure from the Diagram
Implement the classes from the class diagram.
o Create base and subclasses as shown in the diagram.
o Use -private, #protected, or +public access modifiers for attributes and methods.
o Initialize attributes with constructors and use super() for inheritance.
o Implement and override methods as indicated.
Add one additional class for testing.
Create Instances:
o Instantiate a Car object (e.g., "Toyota", "Camry", 2020, "Blue", 5, false);).
o Instantiate a Motorcycle object (e.g. "Harley-Davidson", "Sportster", 2019, "Black", true, "T-Bar" ).
Display detailed information about each vehicle.
Start the engine and for each vehicle. We should see output confirming that engine started.
Honk for each vehicle.
o Car should "Honk Honk!"
o Motorcycle should "Beep Beep!"
Open the roof if the car is convertible.
Modify the make and model values of a Car and display updated values.
o Is it possible to do the same with the instance of the Motorcycle class? Why?
Task 2: Demonstrating Polymorphism
Shape Class
1. Create a superclass called Shape with an instance method DisplayInfo that will return a string containing the name, area and perimeter of the shape.
public String DisplayInfo(){
return "
"+ ShapeName +"
Area="+area+"
Perimeter="+perimeter;
}
The superclass has the following instance variables: ShapeName (String), Area (double) and Perimeter(double). Also create an instance methods setArea and setPerimeter.
2. Create a subclass of Shape called Circle with an instance variable radius (private double) and create a constructor for this subclass. Also create the following instance methods: Area (method that will return the area of a circle), Perimeter (method that will return the perimeter of a circle), and the set and get for the instance variable.
3. Create another subclass of Shape called Rectangle with instance variables (private length and private width) and create a constructor for this subclass. Also create the following instance methods: Area (method that will return the area of a rectangle), Perimeter (method that will return the perimeter of a rectangle) the set and get for the instance variables.
4. Create a class ShapeTest that will demonstrate polymorphism. Create at least two objects to test the two subclasses. Ask for the keyboard input from the user for the needed values to compute the Area and Perimeter for both Circle and Rectangle.

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 Programming Questions!