Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I want the solution in Netbeans and please don\'t forget to add the main method.

ID: 3906115 • Letter: I

Question

I want the solution in Netbeans and please don't forget to add the main method...This is my second time posting this question.

Create an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, and miles per gallon. Include get and set methods for each field. Do not allow the ID to be negative or more than 9999; if it is, set the ID to 0. Do not allow the year to be earlier than 2000 or later than 2017; if it is, set the year to 0. Do not allow the miles per gallon to be less than 10 or more than 60; if it is, set the miles per gallon to 0. Include a constructor that accepts arguments for each field value and uses the set methods to assign the values. Write an application that declares several Automobile objects and demonstrates that all the methods work correctly. Save the files as Automobile.java and TestAutomobiles.java.

Explanation / Answer

class Automobile{

// declaring variables

private int id, year, gallons;

private String make, model, color;

// CONSTRUCTOR

Automobile(int id, int year, int gallons, String make, String model, String color){

setId(id);

setYear(year);

setGallons(gallons);

setMake(make);

setModel(model);

setColor(color);

}

// GETTERS AND SETTERS

void setId(int id){

if(id >= 0 && id <= 9999)

this.id = id;

else

this.id = 0;

}

int getId(){

return id;

}

void setYear(int year){

if(year >= 2000 && year <= 2017)

this.year=year;

else

this.year = 0;

}

int getYear(){

return year;

}

void setGallons(int gallons){

if(gallons >= 10 && gallons <= 60)

this.gallons=gallons;

else

this.gallons = 0;

}

int getGallons(){

return gallons;

}

void setMake(String make){

this.make=make;

}

String getMake(){

return make;

}

void setModel(String model){

this.model=model;

}

String getModel(){

return model;

}

void setColor(String color){

this.color=color;

}

String getColor(){

return color;

}

}

class TestAutomobiles {

public static void main(String[] args) {

// sample runs

Automobile a = new Automobile(1,2015,25,"Car", "BMW", "White");

System.out.println(a.getId());

System.out.println(a.getYear());

System.out.println(a.getGallons());

Automobile b = new Automobile(-23,2,3,"Bike", "Honda", "Black");

System.out.println(b.getId());

System.out.println(b.getYear());

System.out.println(b.getGallons());

}

}

/*OUTPUT

1

2015

25

0

0

0

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote