Question: JAVA CODE ONLY !!! Add another method to the CarDemo class. This method will be called getCarWithMostMilesPerTankOfGas and it will take the three Car objects

JAVA CODE ONLY !!!

JAVA CODE ONLY !!! Add another method to the CarDemo class. This

Add another method to the CarDemo class. This method will be called getCarWithMostMilesPerTankOfGas and it will take the three Car objects and the year the car was made as parameters. The method will return the car that matches the year and can drive the furthest on one tank of gas. The calculation for this is milesPerGallon * sizeOfGasTank. If no car matches the year passed in, have the method return null. In the main method of the CarDemo class, call getCarWithMostMilesPerTankOfGas, passing in the three car object and store the value in a variable called bestCar. Check to see if the bestCar object is null. If so, display no matches. If bestCar is not null (it contains an object), display the car returned.

The outline should look like this...

method will be called getCarWithMostMilesPerTankOfGas and it will take the three Car

com.day1.practice4 Car - carld : int a make : String a model : String - year: String - milesPerGallon : int - sizeOfGasTank : int c Car(int, String, String, String, int, int) getCarld 0 : int getMake0 : String getModel0 : String getYear0: String getMilesPerGallon0 : int getSizeOfGasTank0 : int toString 0 : String CarDemo S main(String []) : void \$ getCarWithBestGasMilage(Car, Car, Car) : Car com.day1.practice4 C Car - carld : int a make : String - model : String a year: String - milesPerGallon : int - sizeOfGasTank : int - Car(int, String, String, String, int, int) c. getCarld0 : int getMake0 : String getModel0 : String getVear0 : String getMilesPerGallon0 : int getSizeOfGasTank0 : int a toString0 : String C. CarDemo S main(String[]) : void \$ getCarWithBestGasMilage(Car, Car, Car) : Car $ getCarWithMostMilesPerTankOfGas(Car, Car, Car, String) : Car

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 Databases Questions!