Looking for answers? Westonci.ca is your go-to Q&A platform, offering quick, trustworthy responses from a community of experts. Ask your questions and receive accurate answers from professionals with extensive experience in various fields on our platform. Join our Q&A platform to connect with experts dedicated to providing accurate answers to your questions in various fields.

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 :

Answer and Explanation:

public class Main {

int Carmodel;

int Purchaseprice;

int Currentyear;

Public void setPurchasePrice(int Purchaseprice){

this.Purchaseprice=Purchaseprice;

}

Public void getPurchasePrice(){

return Purchaseprice;

}

static void printInfo(int Carmodel int Currentyear ){

this.Carmodel=Carmodel;

this.Currentyear=Currentyear;

System.out.println(getPurchasePrice() Carmodel Currentyear);

}

}

The above java program defines a class that has three methods, a get method that returns purchase price of the object, a set method that sets purchase price of the object, and a print method that print out the information about the car object(model, year, price). The print method also takes arguments and assigns values of the arguments/parameters to the object, then prints all.