Car is a class program. Car has a no-args/empty constructor and an overloaded constructor that accepts the year, make, and model and stores each in their respective fields (class-level variables) of the same name. It has a carsBought method that returns the number purchased for that specific year, make, and model through a prompt. Also code a method called objectState that returns the formatted output for the fields according to the specs below.
Expert Answer
class Car
{
private int year;
private String make;
private String model;
public Car() //default constructor
{
year = 0;
make = ” “;
model = ” “;
}
public Car(int year,String make,String model) //argument constructor
{
this.year = year;
this.make = make;
this.model = model;
}
public int carsBought(int y,String mk,String md)// method to find number of cars bought in a particular year
{
int n = 0; //number of cars
if(year == y && make = mk && model = md)
n++;
return n;
}
public void objectState()
{
System.out.printf(“nYear , Make & Model :%d %s %s”,year,make,model);
}
}
class TestCar
{
public static void main (String[] args)
{
Car c1 = new Car(2010,”Ford”,”Ikon”);
c1.objectState();
}
}
Output:
Year , Make & Model :2010 Ford Ikon