Question: /** Test the car class */ public class CarTester { public static void main(String [] args) { Car myCar = new Car(10); // 10 KM

/**
Test the car class
*/
public class CarTester
{
public static void main(String [] args)
{
Car myCar = new Car(10); // 10 KM per litre
double petrolLeft
myCar.addPetrol(20);
myCar.drive(10); // consumes 1 litre
myCar.drive(10); // and another litre
myCar.addPetrol(10);
petrolLeft = myCar.getPetrolInTank();
System.out.print("Petrol left: ");
System.out.println(petrolLeft);
System.out.println("Expected: 28");
System.out.print("KM driven: ");
System.out.println(myCar.getKMDriven());
System.out.println("Expected: 20");
}
}
Write the missing methods of the Calculator class
public class Calculator{
private int x;
public Calculator(int a)
{
x = a;
}
public void add(int y)
{
x += y;
}
//write multiply method
//write divide method
//write method to get the result
}

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!