LAB ACTIVITY 2.6.1: LAB: Car value (classes) 0 / 10 Current file: Car.java Load default template XXXXXXXXXXpublic class Car { private int model Year; 3 // TODO: Declare purchasePrice field (int) 4....

LAB ACTIVITY 2.6.1: LAB: Car value (classes) 0 / 10 Current file: Car.java Load default template... ... 1 public class Car { private int model Year; 3 // TODO: Declare purchasePrice field (int) 4. private int purchasePrice; 5 private int currentValue; 6 7 public void setModel Year(int userYear) 8 9 model Year userYear; 10 11 12 public int getModel Year() 13 14 return model Year; 15 16 17 // TODO: Define setPurchasePrice() method 18 public void setPurchaseprice(int purchasePrice) { } { } LAB ACTIVITY 2.6.1: LAB: Car value (classes) 0/10 Current file: Car.java Load default template... ??? purchasePrice purchasePrice; } // TODO: Define getPurchasePrice() method public int getPurchasePrice() { return purchasePrice; } 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 public void calcCurrentValue(int currentYear) { double depreciationRate = 0.15; int carAge = currentYear model Year; // Car depreciation formula currentValue (int) Math.round(purchasePrice * Math.pow((1 - depreciationRate), carAge)); h LAB ACTIVITY 2.6.1: LAB: Car value (classes) 0/10 Current file: Car.java Load default template... 32 double depreciationRate int carAge currentYear 0.15; model Year; 33 34 // Car depreciation formula currentValue (int) Math.round(purchasePrice * Math.pow((1 - depreciationRate), carAge)); } // TODO: Define printInfo() method to output model Year, purchasePrice, and currentValue public void printInfo() 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 } { System.out.printIn("Car report: "); System.out.printIn(" Model year:"+ model Year); System.out.printIn(" Purchase price:" + purchasePrice); Sytsem.out.printIn(" Current value:"+ currentValue); } 2.6 LAB: Car value (classes) Given main(), complete the Car class (in file Car.java) with methods to set and get the purchase price of a car (setPurchase Price(), 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. LAB ACTIVITY 2.6.1: LAB: Car value (classes) 0 / 10 File is marked as read only Current file: CarValue.java = 4 public class CarValue { 5 public static void main(String[] args) { 6 Scanner scnr = new Scanner(System.in); 7 8 Car myCar = new Car(); 9 10 int user Year scnr.nextInt(); 11 int userPrice scnr.nextInt(); 12 int userCurrent Year = scnr.nextInt(); 13 14 myCar.setModel Year(userYear); 15 myCar.setPurchasePrice(userPrice); 16 myCar.calcCurrentValue(userCurrentYear); 17 18 myCar.printInfo(); 19 } 20 } 21
Nov 22, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here