Question: Given main ( ) , complete the Car class ( in file Car.java ) with methods to set and get the purchase price of a
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 import java.util.Scanner;
import java.lang.Math;
public class CarValue
public static void mainString args
Scanner scnr new ScannerSystemin;
Car myCar new Car;
int userYear scnrnextInt;
int userPrice scnrnextInt;
int userCurrentYear scnrnextInt;
myCar.setModelYearuserYear;
myCar.setPurchasePriceuserPrice;
myCar.calcCurrentValueuserCurrentYear;
myCar.printInfo;
public class Car
private int modelYear;
TODO: Declare purchasePrice field int
private int currentValue;
public void setModelYearint userYear
modelYear userYear;
public int getModelYear
return modelYear;
TODO: Define setPurchasePrice method
TODO: Define getPurchasePrice method
public void calcCurrentValueint currentYear
double depreciationRate ;
int carAge currentYear modelYear;
Car depreciation formula
currentValue int
Math.roundpurchasePrice Math.pow depreciationRate carAge;
TODO: Define printInfo method to output modelYear, purchasePrice, and currentValue
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
