Question: Modify the Car class to include: -equals -interface Write the main program to create an array of size 5 of type Car. Create 5 car

Modify the Car class to include:

-equals

-interface

Write the main program to create an array of size 5 of type Car. Create 5 car objects having each location of the array to refer to one of the cars. Test the pumpGas, goFast, equals method on the array items. Write an enhanced loop to print all the car values (using a toString written last time).

package cartest;

public class Car {

private int tank;

private int speed;

public Car(){

tank = 0;

speed = 0;

}

public int pumpGas(int gas) {

int extra;

if (gas + tank > 20) {

extra = 20-tank;}

else {

extra = gas;

}

tank += gas;

return 4 * gas;

}

public void goFast() {

speed += 5;

}

public String toString() {

return "Car tank is " + tank + ", speed is " + speed + "";

}

}

package cartest;

public class CarTest {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Car car = new Car();

System.out.println(car.pumpGas(15));

car.goFast();

System.out.println(car);

System.out.println(car.pumpGas(12));

car.goFast();

System.out.println(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!