er gallon (mpg). 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 2024; if it is, set the year to 0. Do not allow the miles per gallon to be less than 1
er gallon (mpg). 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 2024; if it is, set the year to 0. Do not allow the miles per gallon to be less than 1
er gallon (mpg). 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 2024; if it is, set the year to 0. Do not allow the miles per gallon to be less than 1
Create an Automobile class for a dealership. Include fields for an ID number (id), make (make), model (model), color (color), year (year), and miles per gallon (mpg).
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 2024; 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 default constructor that accepts no arguments and an overloaded constructor that accepts arguments for each field value and uses the set methods to assign the values.
Part B
Write an application called TestAutomobiles that declares two Automobile objects. Write a function called enterData() that prompts the user for the data values for an Automobile object and returns that object. When you test the program, be sure to enter some invalid data to demonstrate that all the methods work correctly.
An example of the program is shown below:
Enter ID (an integer) >> 12
Enter make >> Mercury
Enter model >> Monterey
Enter color >> Dark Blue
Enter year (4 digits) >> 2007
Enter mpg >> 17
Enter ID (an integer) >> 599
Enter make >> Pontiac
Enter model >> G5
Enter color >> White
Enter year (4 digits) >> 2006
Enter mpg >> 25
ID#12 Mercury Monterey Dark Blue 2007 17.0 miles per gallonID#599 Pontiac G5 White 2006 25.0 miles per gallon
Task 01: Create the Automobile class.
Task 02: Add data fields to the Automobile class.
Task 03: Define the get and set methods for the id data field.
Task 04: Define the get and set methods for the make data field.
Task 05: Define the get and set methods for the model data field.
Task 06: Define the get and set methods for the color data field.
Task 07: Define the get and set methods for the year data field.
Task 08: Define the get and set methods for the mpg data field.
Task 09: Create a default constructor and an overloaded constructor for the Automobile class.
Task 10: Create the TestAutomobiles class.
Task 11: Implement the enterData() function.
Transcribed Image Text:=
C
ge
J Automobile.java
✓ STUDENT [CODESPACES: LITERATE SNIF... J TestAutomobiles.java >
U
J Automobile.class
32
33
J Automobile.java
34
J TestAutomobiles.class
J TestAutomobiles.java
EXPLORER
Solved: Chapter 5 Problem X
Ö https://literate-sniffle-x5wx9wg5x7w4fr5r.github.dev/?folder=/workspaces/9780357673423_java-programming-10e-5...
> OUTLINE
> TIMELINE
Q testautomobiless java che X
€0
> JAVA PROJECTS
> Codespaces: literate sniffle
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
}
}
J TestAutomobiles.java X
auto2.setId(8686);
auto2.setColor("blue");
good declaration
bad declaration
bad ID
MindTap - Cengage Learni X
auto2.setYear (2016);
//calling function to display details of auto2 object after
//changing id, color & year
display(auto2, "change ID, color, and year");
//Function displays yhe details of Automobile object
public static void display (Automobile auto, string msg)
{
//calling set function to set bad value for mpg
auto2.setMpg (4);
//Calling function to display details of auto2 object for bad mpg
display(auto2, "bad mpg");
PROBLEMS OUTPUT
student [Codespaces: literate sniffle]
//calling set function to set good value for mpg
auto2.setMpg (30);
//Calling function to display details of auto2 object for good mpg
display(auto2, "good mpg");
System.out.println(msg + " " + auto.getId() +
|"" + auto.getMake() + " " + auto.getModel() +
+ auto.getColor() + " " +
auto.getYear() + " " + auto.getMpg() + " miles per gallon");
BARZA
Why the
WESKEINE
PANE
www
2015040
Companion - student [Cod X
wana
Companion X
Success Confirmation of Q X
All
DEBUG CONSOLE TERMINAL PORTS 1
1451 Chevrolet Camaro red 2010 24.5 miles per gallon
Ford Focus white 0 0.0 miles per gallon
e Chevrolet Camaro red 2010 24.5 miles per gallon
good ID
2222 Chevrolet Camaro red 2010 24.5 miles per gallon
change make and model 2222 Toyota Corolla red 2010 24.5 miles per gallon
change ID, color, and year 8686 Ford Focus blue 2016 0.0 miles per gallon
bad mpg
8686 Ford Focus blue 2016 0.0 miles per gallon
good mpg
8686 Ford Focus blue 2016 30.0 miles per gallon
→.../9788357673423_java-programming-18e-5d83f9ac-c9c6-4288-9e22-37326c529145/chapters/ex88/student (terplate) $
o @jbowen3225
001 Java: Lightweight Mode
{}
(1)
+
·1+
How to Use the Code Editor
1. Select the "Run Code" button to execute the program.
2. Select the "Calculate Grade" button to generate a score based on the
completed tasks.
3. Continue to modify, run, and calculate your code until you are happy
with the grade.
4. Select the "Submit" button to turn in the assignment to your
instructor.
Part A
Create an Automobile class for a dealership. Include fields for an ID number
(id), make (make), model (model), color (color), year (year), and miles per
gallon (mpg).
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 O. Do not allow the year to
be earlier than 2005 or later than 2024; 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 default constructor that accepts no arguments and an overloaded
constructor that accepts arguments for each field value and uses the set
+
☐☐☐0⁹
B
4
*
+v...
...
bash
Program O....
Layout: US O
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
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.