72.3k views
2 votes
Given main(), complete the Car class (in file Car.java) with methods to set and get the purchase price of a car (setPurchasePrice(), getPurchasePrice()), and to output the car's information (printInfo()).

Ex: If the input is:_______.
2011
18000
2018

User Lymari
by
4.9k points

1 Answer

1 vote

Answer:

Step-by-step explanation:

This a java code for a car and can be written as follows:

public class Car {

private int modelYear;

private int purchasePrice;

private int currentValue;

public int getModelYear() {

return modelYear;

}

public void setModelYear(int modelYear) {

this.modelYear = modelYear;

}

public int getPurchasePrice() {

return purchasePrice;

}

public void setPurchasePrice(int purchasePrice) {

this.purchasePrice = purchasePrice;

}

public int getCurrentValue() {

return currentValue;

}

public void calcCurrentValue(int year) {

int age = year - modelYear;

currentValue = (int) Math.round(purchasePrice * Math.pow(0.85, age));

}

public void printInfo() {

System.out.println("Car's information:");

System.out.println(" Model year: " + modelYear);

System.out.println(" Purchase price: " + purchasePrice);

System.out.println(" Current value: " + currentValue);

}

}

User Alejandro Vargas
by
3.6k points