IDNLearn.com: Your destination for reliable and timely answers to any question. Join our community to receive prompt and reliable responses to your questions from experienced professionals.

java 7.24 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 (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.

Sagot :

Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible.

How to write the program?

Java Classes/Objects Java is an object-oriented programming language. Everything in Java is associated with classes and objects, along with its attributes and methods.

public class Car {

   // instance variables

   private int modelYear;

   private int purchasePrice;

   private int currentYear;

   

   // constructor

   public Car(int modelYear, int purchasePrice, int currentYear) {

       this.modelYear = modelYear;

       this.purchasePrice = purchasePrice;

       this.currentYear = currentYear;

   }

   

   // setter method

   public void setPurchasePrice(int price) {

       this.purchasePrice = price;

   }

   

   // getter method

   public int getPurchasePrice() {

       return this.purchasePrice;

   }

   

   // method to output car's information

   public void printInfo() {

       int age = this.currentYear - this.modelYear;

       int value = (int) (this.purchasePrice * Math.pow(0.9, age));

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

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

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

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

   }

}

To Know More About Classes, Check Out

https://brainly.com/question/28212543

#SPJ1