Question & Answer: Car is a class program. Car has a no-args/empty constructor and an overloaded constructor that ac…..

JAVA-EXAM 3 SUMMER 2017 INSTRUCTOR: A SAHBA NAME S 2033-SECTION DATE l. Coding. Analysis, and Interpretation: For all problems follow proper coding guidelines with regard to punctuation, spacing, syntax, etc. Use printfo (with format specifiers as needed) for prompts and output. Do not write in all caps except where permitted according to Java Class programs are programs without a mainO. Fields and methods in stand-alone class programs are not static. Application classes are programs with a mainO. Be sure to exit the maing. Unless otherwise indicated, classes and their Test programs are in the same directory. READ carefully all the instructions. 31. 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 retuns 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. (10 points) FORMATTED OUTPUT SPECS: Year, Make, & Model: 9999 Xxoooxx Xxoocooooxx
Need answered within 30 minutes!!

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

Still stressed from student homework?
Get quality assistance from academic writers!