Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/** 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
}Also, write a program to do this calculation using the Calculator:
(10+12) * 14 / 3
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