Get the information you need with the help of IDNLearn.com's extensive Q&A platform. Our platform offers detailed and accurate responses from experts, helping you navigate any topic with confidence.
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
Your engagement is important to us. Keep sharing your knowledge and experiences. Let's create a learning environment that is both enjoyable and beneficial. Your search for solutions ends here at IDNLearn.com. Thank you for visiting, and come back soon for more helpful information.