48 lines
1.3 KiB
Java
Raw Normal View History

2020-11-11 08:47:37 -05:00
public class Car {
private int modelYear;
// TODO: Declare purchasePrice field (int)
private int purchasePrice;
private int currentValue;
public void setModelYear(int userYear){
modelYear = userYear;
}
public int getModelYear() {
return modelYear;
}
// TODO: Define setPurchasePrice() method
public void setPurchasePrice(int userPrice) {
purchasePrice = userPrice;
}
// TODO: Define getPurchasePrice() method
public int getPurchasePrice() {
return purchasePrice;
}
public int getCurrentValue() {
return currentValue;
}
public void calcCurrentValue(int currentYear) {
double depreciationRate = 0.15;
int carAge = currentYear - modelYear;
// Car depreciation formula
currentValue = (int)
Math.round(purchasePrice * Math.pow((1 - depreciationRate), carAge));
}
// TODO: Define printInfo() method to output modelYear, purchasePrice, and currentValue
public void printInfo() {
System.out.println("Car's information:");
System.out.println(" Model year: " + getModelYear()); // Just to show I can do it
System.out.println(" Purchase price: " + purchasePrice); //No idea why it bothered with getPurchasePrice()
System.out.println(" Current value: " + currentValue);
}
}