Java. Modify a dealership's Automobile class so it includes fields for an id (ID number), make, model, color, year, and mpg (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 2005 or later than 2019; 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. The TestAutomobile.java file has been provided to test your implementation.   Here is the code so far: public class Automobile {     private int id;     private String make;     private String model;     private String color;     private int year;     private double mpg;     public Automobile(int id, String make, String model, String color,                       int year, double mpg) {     }     public void setId(int id) {     }     public void setMake(String make) {     }     public void setModel(String model) {     }     public void setColor(String color) {     }     public void setYear(int yr) {     }     public void setMpg(double mpg) {     }     public int getId() {     }     public String getMake() {     }     public String getModel() {     }     public String getColor() {     }     public int getYear() {     }     public double getMpg() {     } }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter5: Making Decisions
Section: Chapter Questions
Problem 8PE
icon
Related questions
Question

Java.

Modify a dealership's Automobile class so it includes fields for an id (ID number), make, model, color, year, and mpg (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 2005 or later than 2019; 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.

The TestAutomobile.java file has been provided to test your implementation.

 

Here is the code so far:

public class Automobile {
    private int id;
    private String make;
    private String model;
    private String color;
    private int year;
    private double mpg;
    public Automobile(int id, String make, String model, String color,
                      int year, double mpg) {
    }
    public void setId(int id) {
    }
    public void setMake(String make) {
    }
    public void setModel(String model) {
    }
    public void setColor(String color) {
    }
    public void setYear(int yr) {
    }
    public void setMpg(double mpg) {
    }
    public int getId() {
    }
    public String getMake() {
    }
    public String getModel() {
    }
    public String getColor() {
    }
    public int getYear() {
    }
    public double getMpg() {
    }
}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT