Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How will the proposed strategy prevent conflict?

Answered: 1 week ago

Question

Q .1. Different ways of testing the present adulterants ?

Answered: 1 week ago

Question

Q.1. Health issues caused by adulteration data ?

Answered: 1 week ago

Question

1. Traditional and modern methods of preserving food Articles ?

Answered: 1 week ago

Question

What is sociology and its nature ?

Answered: 1 week ago