Question: Why am I getting 2 java errors cannot find symbol ? public class TestAutomobiles { public static void main(String[] args) { //Valid arguments for automobile
Why am I getting 2 java errors "cannot find symbol" ?
public class TestAutomobiles { public static void main(String[] args) { //Valid arguments for automobile class Automobile automobile1 = new Automobile(1234, "Caddillac", "STS", "Silver", 2005, 22); //print using get methods System.out.println("ID: "+automobile1.getID()); System.out.println("Make: "+automobile1.getMake()); System.out.println("Model: "+automobile1.getModel()); System.out.println("Color: "+automobile1.getColor()); System.out.println("Year: "+automobile1.getYear()); System.out.println("MPG: "+automobile1.getMPG()); //invalid arguments for automobile class //Negative ID number, Year less than 2000, MPG more than 60 Automobile automobile2 = new Automobile(-1234,"Caddillac", "STS", "Silver", 1999, 61); //print using get methods System.out.println("ID: "+automobile2.getID()); System.out.println("Make: "+automobile2.getMake()); System.out.println("Model: "+automobile2.getModel()); System.out.println("Color: "+automobile2.getColor()); System.out.println("Year: "+automobile2.getYear()); System.out.println("MPG: "+automobile2.getMPG()); } }
HERE IS THE Automobile class that is being tested.
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) { setID(ID); this.make = make; this.model = model; this.color = color; setYear(year); setMPG(mpg); } public void setID(int ID) { //checking to see if ID is less thatn 0 or more than 9999 if(ID<0 ||id> 9999) this.ID = 0; else this.ID = ID; } public int getID() { return ID; } //methods for set/get make value public void setMake(String make) { this.make = make; } public String getmake() { return make; } //method to set/get model value public void setModel(String model) { this.model = model; } public String getModel() { return model; } //method to set/get color value public void setColor(String color) { this.color = color; } public String getColor() { return color; }
//method to set/get year value public void setYear(int year) { //checking to see if year is less than 2000 or more than 2017 if(year < 2000 || year > 2017) this.year = 0; else this.year = year; } public int getYear() { return year; } //method to set/get mpg value public void setMPG(double mpg) { //checking to see if miles are less than 10 or more than 60 if(mpg < 10 || mpg > 60) this.mpg = 0; else this.mpg = mpg; } public double getMPG() { return mpg; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
