Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I solved the following excercise: Implement a class Car, that has the following

ID: 3717994 • Letter: I

Question

I solved the following excercise:

Implement a class Car, that has the following characteristics:

a) brandName,

b) priceNew, which represents the price of the car when it was new,

c) color, and

d) odometer.

The class should have:

A method getPriceAfterUse() which should return the price of the car after being used according to the following formula:

car price after being used = priceNew ? (1? odometer ) 600,000

A method updateMilage(double traveledDistance) that changes the current state of the car by increasing its milage, and

A method outputDetails() that will output to the screen all the information of the car, i.e., brand name, price new, price used, color, and odometer.

and this is my code:

public class Car {
String brandName;
double priceNew;
String color;
double odometer;
public double getPriceAfterUse(){

return (priceNew * (1-(odometer/600000)));

}
public void updateMilage(double travelDistance) {
odometer+= travelDistance;
}
public String outputDetails() {
return ("Car brand name:- " + brandName + " Car price (new):- " + priceNew+
" price used:- "+getPriceAfterUse()+" Car color:- "+color+
" odometer:- " +odometer );

  
}

}

but i dunno how to slove this one which's related to the previous one:

Write a test class for the Car class above. You are required to do the followings:

A. Create an object of type Car.

B. Assign any valid values to the instance variables of the object created in ‘A’. C. Use the method getPriceAfterUse on the object created in ‘A’ then output the result to the screen.

D. Use the method updateMilage on the object created in ‘A’ by passing a valid value. E. Do part ‘C’ again.

F. Use the method outputDetails on the object created in ‘A’.

Explanation / Answer

public class Car {

String brandName;

double priceNew;

String color;

double odometer;

public double getPriceAfterUse() {

return (priceNew * (1 - (odometer / 600000)));

}

public void updateMilage(double travelDistance) {

odometer += travelDistance;

}

public String outputDetails() {

return ("Car brand name:- " + brandName + " Car price (new):- " + priceNew + " price used:- "

+ getPriceAfterUse() + " Car color:- " + color + " odometer:- " + odometer);

}

}

-----------------------------------------------------------------------------------------------------------------------------------------------------

// Test class

-------------------

public class CarTest {

public static void main(String[] args) {

Car car = new Car();

car.brandName = "Jaguar XF";

car.color = "black";

car.odometer = 20000.5;

car.priceNew = 4000000.0;

// prints the car price after use

System.out.println("Car Price After Use : " + car.getPriceAfterUse());

car.updateMilage(130.2);

System.out.println();

System.out.println("Details");

System.out.println("--------------------------------");

// prints the details

System.out.println(car.outputDetails());

}

}