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

Instructions Complete the code below, some of which is valid code and some pseud

ID: 3716413 • Letter: I

Question

Instructions

Complete the code below, some of which is valid code and some pseudo code that needs to be fleshed out and clearly commented. Submit your pseudo code and flowcharts, finished code, and a test run of the code in two documents. Cite all sources which have informed your coding. Share the process of completing this assignment.

public class TestAutomobiles

{

public static void main(String[] args)

{

Create a new Automobile(1451, "Chevrolet", "Camaro", "red", 2010, 24.5);

Create another new Automobile(145188, "Ford", "Focus", "white", 2019, 75);

Display auto1 information

Display auto2 information

auto1.setId(-3);

display(auto1, "bad ID");

auto1.setId(2222);

display(auto1, "good ID");

auto1.setMake("Toyota");

auto1.setModel("Corolla");

display(auto1, "chnage 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)

{

Screen print a message, an ID, a make, a model , a color, a year, milage per gallon

}

}

public class Automobile

{

private int id;

private String make;

private String model;

private String color;

private int year;

private double mpg;

// Constructor

public Automobile(int id, String make, String model, String color,

int year, double mpg)

{

setId(id);

setMake(make);

setModel(model);

setColor(color);

setYear(year);

setMpg(mpg);

}

// setters

Set setId(int id)

Set setMake(String make)

Set setModel(String model)

Set setColor(String color)

Set year setYear(int yr)

Set setMpg(double mpg)

{

//Getters

Getter for getId()

Getter for getMake()

Getter for getModel()

Getter for getColor()

Getter for getYear()

Getter for getMpg()

}

Explanation / Answer

Below is your code

Automobile.java

//Class Declaration

public class Automobile

{

//instance variable declaration

private int id;

private String make;

private String model;

private String color;

private int year;

private double mpg;

// Constructor - Parametrized

public Automobile(int id, String make, String model, String color,

int year, double mpg)

{

//calling all setters to set the parameters passed in Constructor

setId(id);

setMake(make);

setModel(model);

setColor(color);

setYear(year);

setMpg(mpg);

}

//getter and setter for id

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

//getter and setter for make

public String getMake() {

return make;

}

public void setMake(String make) {

this.make = make;

}

//getter and setter for model

public String getModel() {

return model;

}

public void setModel(String model) {

this.model = model;

}

//getter and setter for color

public String getColor() {

return color;

}

public void setColor(String color) {

this.color = color;

}

//getter and setter for year

public int getYear() {

return year;

}

public void setYear(int year) {

this.year = year;

}

//getter and setter for mpg

public double getMpg() {

return mpg;

}

public void setMpg(double mpg) {

this.mpg = mpg;

}

//toString method to display the Automobile detail

public String toString() {

return "id=" + id + " make=" + make + " model=" + model + " color=" + color + " year=" + year

+ " mpg=" + mpg ;

}

}

TestAutomobiles.java

//Class to test Automobile class

public class TestAutomobiles

{

//main method to execute the program

public static void main(String[] args)

{

//Creating object 1 of Automobile

Automobile auto1 = new Automobile(1451, "Chevrolet", "Camaro", "red", 2010, 24.5);

//Creating object 2 of Automobile

Automobile auto2 = new Automobile(145188, "Ford", "Focus", "white", 2019, 75);

//Displaying object 1 and object 2

System.out.println(auto1.toString());

System.out.println(auto2.toString());

//setting/changing ID of object 1

auto1.setId(-3);

//displaying the changed object

display(auto1, "bad ID");

//setting/changing the ID of object 1

auto1.setId(2222);

//displaying the changed object

display(auto1, "good ID");

//setting/changing make and model of object 1

auto1.setMake("Toyota");

auto1.setModel("Corolla");

//displaying the changed object

display(auto1, "chnage make and model");

//setting id,color,year of object 2

auto2.setId(8686);

auto2.setColor("blue");

auto2.setYear(2016);

//displaying the changed object

display(auto2, "change ID, color, and year");

//setting mpg of object 2

auto2.setMpg(4);

//displaying changed object

display(auto2, "bad mpg");

//setting mpg of object 2

auto2.setMpg(30);

//displaying changed object

display(auto2, "good mpg");

}

//method to display object and message

public static void display(Automobile auto, String msg)

{

System.out.println(msg);

System.out.println(auto.toString());

}

}

Output

id=1451
make=Chevrolet
model=Camaro
color=red
year=2010
mpg=24.5
id=145188
make=Ford
model=Focus
color=white
year=2019
mpg=75.0
bad ID
id=-3
make=Chevrolet
model=Camaro
color=red
year=2010
mpg=24.5
good ID
id=2222
make=Chevrolet
model=Camaro
color=red
year=2010
mpg=24.5
chnage make and model
id=2222
make=Toyota
model=Corolla
color=red
year=2010
mpg=24.5
change ID, color, and year
id=8686
make=Ford
model=Focus
color=blue
year=2016
mpg=75.0
bad mpg
id=8686
make=Ford
model=Focus
color=blue
year=2016
mpg=4.0
good mpg
id=8686
make=Ford
model=Focus
color=blue
year=2016
mpg=30.0