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 : 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 eg "Toyota", "Camry", "Blue", false;
o Instantiate a Motorcycle object eg "HarleyDavidson", "Sportster", "Black", true, TBar"
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 : Demonstrating Polymorphism
Shape Class
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
Areaarea
Perimeterperimeter;
The superclass has the following instance variables: ShapeName String Area double and Perimeterdouble Also create an instance methods setArea and setPerimeter.
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.
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.
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
