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() {     } }     Code for TestAutomobiles.java:   public class TestAutomobiles {    public static void main(String[] args)    {       Automobile auto1 = new Automobile(1451, "Chevrolet", "Camaro", "red", 2010, 24.5);       Automobile auto2 = new Automobile(145188, "Ford", "Focus", "white", 2020, 75);       display(auto1, "good declaration");       display(auto2, "bad declaration");       auto1.setId(-3);       display(auto1, "bad ID");       auto1.setId(2222);       display(auto1, "good ID");       auto1.setMake("Toyota");       auto1.setModel("Corolla");       display(auto1, "change make and model");       auto2.setId(8686);       auto2.setColor("blue");       auto2.setYear(2016);       display(auto2, "change ID, color, and year");       auto2.setMpg(4);       display(auto2, "bad mpg");       auto2.setMpg(30);       display(auto2, "good mpg");    }    public static void display(Automobile auto, String msg)    {       System.out.println(msg + "    " + auto.getId() +          " " + auto.getMake() + " " + auto.getModel() +          " " + auto.getColor() + " " +         auto.getYear() + " " + auto.getMpg() + " miles per gallon");    } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

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() {
    }
}
 
 
Code for TestAutomobiles.java:
 
public class TestAutomobiles
{
   public static void main(String[] args)
   {
      Automobile auto1 = new Automobile(1451, "Chevrolet", "Camaro", "red", 2010, 24.5);
      Automobile auto2 = new Automobile(145188, "Ford", "Focus", "white", 2020, 75);
      display(auto1, "good declaration");
      display(auto2, "bad declaration");
      auto1.setId(-3);
      display(auto1, "bad ID");
      auto1.setId(2222);
      display(auto1, "good ID");
      auto1.setMake("Toyota");
      auto1.setModel("Corolla");
      display(auto1, "change make and model");
      auto2.setId(8686);
      auto2.setColor("blue");
      auto2.setYear(2016);
      display(auto2, "change ID, color, and year");
      auto2.setMpg(4);
      display(auto2, "bad mpg");
      auto2.setMpg(30);
      display(auto2, "good mpg");
   }
   public static void display(Automobile auto, String msg)
   {
      System.out.println(msg + "    " + auto.getId() +
         " " + auto.getMake() + " " + auto.getModel() +
         " " + auto.getColor() + " " +
        auto.getYear() + " " + auto.getMpg() + " miles per gallon");
   }
}  
 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY