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 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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

This is the 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 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.

This is the code it gives. 
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() {
    }
}
 
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 2 images

Blurred answer
Knowledge Booster
Class
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education