Question: Car Subclass Purpose: The Car class represents a specific type of vehicle with unique attributes and behaviors specific to cars. Attributes: numberOfDoors ( int )

Car Subclass
Purpose:
The Car class represents a specific type of vehicle with unique attributes and behaviors specific to cars.
Attributes:
numberOfDoors (int): Represents the number of doors on the car. This attribute should be private to Car.
Constructor:
A constructor that takes speed, fuel, and numberOfDoors as parameters. It should call the Vehicle constructor to initialize speed and fuel, and set numberOfDoors.
Methods:
start(): Override the start() method to print a custom message indicating that the car has started. Students should decide if they want to call the Vehicle classs start() method as part of this method.
honk(): A method that prints a message indicating the car horn sound, such as Beep Beep!
Additional Considerations:
Add getter and setter methods for numberOfDoors if students plan to modify this attribute outside of the class.
Bicycle Subclass
Purpose:
The Bicycle class represents a specific type of vehicle with unique attributes and behaviors specific to bicycles.
Attributes:
hasBell (boolean): Represents whether the bicycle has a bell. This attribute should be private to Bicycle.
Constructor:
A constructor that takes speed, fuel, and hasBell as parameters. It should call the Vehicle constructor to initialize speed and fuel, and set hasBell.
Methods:
start(): Override the start() method to print a custom message indicating that the bicycle has started. This message could include something specific to bicycles, such as "Pedal away!"
ringBell(): A method that checks if hasBell is true. If it is, print a message indicating the bell sound, like "Ring Ring!" If hasBell is false, print a message indicating the bicycle has no bell.
Additional Considerations:
Add getter and setter methods for hasBell if students plan to modify this attribute outside of the class.
Main Class
Purpose:
The Main class is the driver class for the project. In this class, students will create instances of Car and Bicycle and test their methods.
Instructions for Main Class:
Create a Car Object: Instantiate a Car object, passing in values for speed, fuel, and numberOfDoors.
Test the methods by calling start(), displayFuel(), and honk() on the Car object.
Create a Bicycle Object: Instantiate a Bicycle object, passing in values for speed, fuel, and hasBell.
Test the methods by calling start(), displayFuel(), and ringBell() on the Bicycle object.
Additional Tasks for Students:
Experiment with creating different Car and Bicycle objects with varied values for the attributes.
Test the effects of access specifiers by attempting to access attributes and methods directly from Main.

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!