Question: Implement a class named Car.java. Draw a UML class diagram as explained in the class. The attributes of the class are: Make yearModel mileage fuelAmount
Implement a class named Car.java. Draw a UML class diagram as explained in the class. The attributes of the class are:
Make
yearModel
mileage
fuelAmount
time
The methods of the class are:
setMake
setYearModel
setMileage
setFuelAmount
setTime
getMake
getYearModel
getMileage
getFuelAmount
getTime
getDistanceTraveled
getSpeed
The distance traveled by a car is calculated using following formula:
Distance Traveled = Mileage * Fuel Amount (in gallons)
Accept the values for the mileage and amount of fuel in gallons from the keyboard. For example, if you enter from the keyboard, the mileage as 20 and amount of fuel as 10 gallons then distance traveled will be 200 miles.
The speed of a car is calculated using following formula:
Speed = Distance Traveled / Time
You will get the distance traveled from the above formula. Enter the time from the keyboard. For example distance traveled is 200 miles and time entered is 3 hours then speed of the car will be 66.67 miles per hour.
Then implement a CarDemo.java program to verify the functionality of the Car.java class. In the CarDemo.java program create four objects (Toyota, Honda, Ford and Volvo) of the class Car and check the functionality of the class Car.java for each object. You will have to implement this program in two versions. In first version accept the input from the keyboard using Scanner class and another version of the program using JOptionPane class.
The output of your program should display make, model year, mileage, fuel amount, time, distance traveled and speed of the car.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
