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.
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
We appreciate your time. Please come back anytime for the latest information and answers to your questions. Thank you for choosing our platform. We're dedicated to providing the best answers for all your questions. Visit us again. Get the answers you need at Westonci.ca. Stay informed by returning for our latest expert advice.