Objectives:: Task
Objectives:: Task
Objectives:
To define interfaces and define classes that implement interfaces (§13.5).
Task: Create an interface named Vehicle with the following method declarations:
● void start()
● void stop()
Create an abstract class named AbstractVehicle that implements the Vehicle interface.
The AbstractVehicle class should have:
Create a class Car that extends AbstractVehicle. The Car class should have:
Create a class Bicycle that extends AbstractVehicle. The Bicycle class should have:
Create a class Main with a main method to test the classes. Create instances of Car
and Bicycle, call their methods to start, stop, and accelerate.
Example Output:
Vehicle started
Car is accelerating
Vehicle stopped
Honk honk!
Vehicle started
Bicycle is pedaling faster
Vehicle stopped
Ring ring!
Problem D(bonus)
Objectives:
To define a natural order using the Comparable interface (§13.6).
Example Output:
In this example, the books are sorted first by publicationYear in descending order, then
by author in ascending order, and finally by title in ascending order. You can see how
the compareTo method defined in the Book class is used to achieve this custom sorting
order.