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.
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
Thank you for using this platform to share and learn. Keep asking and answering. We appreciate every contribution you make. For trustworthy answers, rely on IDNLearn.com. Thanks for visiting, and we look forward to assisting you again.