Application that shows how class inherit from parent class and implement an interface Solved
Designing an application that shows how class inherit from parent class and implement an interface.
Specifications Class diagram has been provided to follow
<<Interface
Vehicle
+drive() : void
+stop() : boolean
+steer : (int)
Car
+doors : Integer
+wheels : Integer
+color : String
Car()
+drive() : void
+stop() : boolean
+steer(int) : void
Ferrari
+Badge : String
+Year : Integer
+Price : Double
Truck
+Gear : Integer
+horn : Integer
Truck()
+drive() : void
+stop() : boolean
+steer(int) : void
+honk() : void
Ford
Ford()
+drive() : void
+stop() : void
+steer(int) : void
+honk() : void
Input
No user input require
Processing
For each class created output the total to the screen.
proper use to package is necessary all sub classes must override toString method with simple String message, use System.out.println statement for output create instance variables and method shown in Class diagram for all classes create an interface called Vehicle create a parent class called Car which implements Vehicle interface create a parent class called Truck which implements Vehicle interface create a child class called Ferrari which extends from Car class create a child class called Ford which extends from Truck class create a class called TestClass with main method create instance variable of type ArrayList in TestClass to hold instance of Ferrari and Truck classes add few instances of both classes into ArrayList object loop over ArrayList and call display method of objects in ArrayList Output
The following is a sample run of the program:
Ferrari class: ### I'm a Ferrari car, my color is (some color) and have (no. of doors) doors ###
Ford class: *** I'm a Ford truck, and I have (no of gears) gears ***