Question
In Java, have the sample output look like this: Output from the showVehicle method In this application, a passenger car is an every day vehicle
In Java, have the sample output look like this:
Output from the showVehicle method In this application, a passenger car is an every day vehicle registered to an individual make=Ford, model=Mustang, year=2016, price=44500.0 PassCar numPass=5, AC=true Motor EcoBoost, cylinders=6, bhp=310, displacement=2.3
In this application, a Truck is a vehicle designed to transport cargo make=Dodge, model=Ram, year=2016, price=46000.0 Truck type=pickup, capacity=1500 Motor Hemi, cylinders=8, bhp=707, displacement=5.7
In this application, a passenger car is an every day vehicle registered to an individual make=Tesla, model=Model S, year=2016, price=121000.0 PassCar numPass=2, AC=true Motor P90D, cylinders=0, bhp=762, displacement=0.0
Output from ArrayList in main
make=Ford, model=Mustang, year=2016, price=44500.0 PassCar numPass=5, AC=true Motor EcoBoost, cylinders=6, bhp=310, displacement=2.3
make=Dodge, model=Ram, year=2016, price=46000.0 Truck type=pickup, capacity=1500 Motor Hemi, cylinders=8, bhp=707, displacement=5.7
make=Tesla, model=Model S, year=2016, price=121000.0 PassCar numPass=2, AC=true Motor P90D, cylinders=0, bhp=762, displacement=0.
The task,
Create the four classes as per the above UML diagram. Do NOT add any attributes or methods that don't appear in the UML diagrams. Don't modify anything, either. Create an executable class named TestVehicle test your work. In TestCollege, add code that accomplishes the tasks below. The sample output might assist you to understand these tasks.
In the main method of TestVehicle:
instantiate a Motor object for each vehicle you will code.
instances as follows:
make two objects with declared type Vehicle but actual type PassCar.
make at least one object of declared type Vehicle but actual type Truck.
make an array of type Object with the instances created above.
execute a void method named showVehicle (see below) with the Object array as sole argument.
create an Object Arraylist from the array already created. See page 439.
use a for loop to run through the ArrayList and display each object's data.
In the showVehicle method:
use a foreach loop to process the Object array.
for each Object, display the description method followed by the toString method. This will require using the instanceof operator and casting.
Vehicle -make: String -model : String -year: int -price: double +Vehicle(make in rice double +description):void +toString):String PassCar Truck numPass: int AC: boolean -motor: Motor : String -capacity:int -motor: Motor +PassCar(make:String,model:String,year:int,price: double,numPass:int,AC:Boolean,motor:Motor) +description():void +toString():String +Vehicle(make:String,model:String,year:int,price: double,type:String,capacity:int,motor:Motor) +description):void +toString):String Motor -name: String -cylinders: int bhp: int -displacement: double +Motor(na displacement:double +toString):String ri
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started