Question
car (setPurchasePrice(), getPurchasePrice()), and to output the car's information (printInfo()). Ex: If the input is: 2011 18000 2018 where 2011 is the car's model year,
car (setPurchasePrice(), getPurchasePrice()), and to output the car's information (printInfo()).
Ex: If the input is:
2011
18000
2018
where 2011 is the car's model year, 18000 is the purchase price, and 2018 is the current year, the output is:
Car's information:
Model year: 2011
Purchase price: 18000
Current value: 5770
Note: printInfo() should use three spaces for indentation. Also note that CarValue.java is marked as read only, Car.java can be edited though.
/* CarValue.java */
import java.util.Scanner; import java.lang.Math;
public class CarValue { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Car myCar = new Car(); int userYear = scnr.nextInt(); int userPrice = scnr.nextInt(); int userCurrentYear = scnr.nextInt(); myCar.setModelYear(userYear); myCar.setPurchasePrice(userPrice); myCar.calcCurrentValue(userCurrentYear); myCar.printInfo(); } }
/* Car.java */
public class Car { private int modelYear; // TODO: Declare purchasePrice field (int)
private int currentValue; public void setModelYear(int userYear){ modelYear = userYear; } public int getModelYear() { return modelYear; } // TODO: Define setPurchasePrice() method // TODO: Define getPurchasePrice() method 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 }
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