Answer:
Here is the implementation of the Car class:
class Car {
private String model;
private String year;
private double price;
public Car(String model, String year, double price) {
this.model = model;
this.year = year;
if (price > 0) {
this.price = price;
}
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
if (price > 0) {
this.price = price;
}
}
}
Here is the test application that demonstrates the capabilities of the Car class:
class CarApplication {
public static void main(String[] args) {
Car car1 = new Car("Toyota", "2020", 20000);
Car car2 = new Car("Honda", "2019", 25000);
System.out.println("Original price of car1: $" + car1.getPrice());
System.out.println("Original price of car2: $" + car2.getPrice());
car1.setPrice(car1.getPrice() * 0.95);
car2.setPrice(car2.getPrice() * 0.93);
System.out.println("Discounted price of car1: $" + car1.getPrice());
System.out.println("Discounted price of car2: $" + car2.getPrice());
}
}