Looking for trustworthy answers? Westonci.ca is the ultimate Q&A platform where experts share their knowledge on various topics. Join our platform to connect with experts ready to provide precise answers to your questions in various areas. Experience the convenience of finding accurate answers to your questions from knowledgeable experts on our platform.

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