My code is getting a small error that is refusing to let me entire code compile.
Take a look.
//THIS IS ASSIGNMENT 4, MAIN METHOD
import java.io.*; //to use InputStreamReader and BufferedReader
import java.util.*;
public class Assignment4
{
public static void main (String[] args)
{
// local variables, can be accessed anywhere from the main method
char input1 = 'Z';
String inputInfo;
String year, color;
double price;
String country, manufacturer, brand;
String line = new String();
// instantiate a Pet object
Car car1 = new Car();
printMenu();
//Create a Scanner object to read user input
Scanner scan = new Scanner(System.in);
do // will ask for user input
{
System.out.print("What action would you like to perform?\n");
line = scan.nextLine();
if (line.length() == 1)
{
input1 = line.charAt(0);
input1 = Character.toUpperCase(input1);
// matches one of the case statement
switch (input1)
{
case 'A': //Add Car
System.out.print("Please enter the car information:\n");
System.out.print("Who is the car\'s manufacturer?\n");
manufacturer = scan.nextLine();
System.out.print("What is the car brand?\n");
brand = scan.nextLine();
System.out.print("Which country is the car made?\n");
country = scan.nextLine();
car1.setMakes(country, manufacturer, brand);
System.out.print("what year was the car made?\n");
year = scan.nextLine();
car1.setYear(year);
System.out.print("What color is the car?\n");
color = scan.nextLine();
car1.setColor(color);
System.out.print("How much was the car\'s price?\n");
//price = scan.nextDouble();
price = Double.parseDouble(scan.nextLine());
car1.setPrice(price);
break;
case 'D': //Display Pet
System.out.print(car1);
break;
case 'Q': //Quit
break;
case '?': //Display Menu
printMenu();
break;
default:
System.out.print("Unknown action\n");
break;
}
}
else
{
System.out.print("Unknown action\n");
}
} while (input1 != 'Q' || line.length() != 1);
}
/** The method printMenu displays the menu to a user **/
public static void printMenu()
{
System.out.print("Choice\t\tAction\n" +
"------\t\t------\n" +
"A\t\tAdd a Car\n" +
"D\t\tDisplay Car\n" +
"Q\t\tQuit\n" +
"?\t\tDisplay Help\n\n");
}
}
//THIS IS MAKES CLASS
public class Makes
{
private String country;
private String manufacturer;
private String brandName;
public Makes()
{
country = "?";
manufacturer = "?";
brandName = "?";
}
public Makes(String nCountry, String nManufac, String nBrand)
{
country = nCountry;
manufacturer = nManufac;
brandName = nBrand;
}
public String getCountry()
{
return country;
}
public String getManufac()
{
return manufacturer;
}
public String getBrand()
{
return brandName;
}
public void setCountry(String nCountry)
{
country = nCountry;
}
public void setManufac(String nManufac)
{
manufacturer = nManufac;
}
public void setBrand(String nBrand)
{
brandName = nBrand;
}
public String toString()
{
String result;
result = country + "," + manufacturer + "," + brandName;
return result;
}
}
//THIS IS CAR CLASS
public class Car
{
private String year;
private String color;
private double price;
private Makes make;
public Car()
{
year = "?";
color = "?";
price = 0;
}
public Car(String Years, String Colors, double Prices)
{
year = Years;
color = Colors;
price = Prices;
}
public String getYear()
{
return year;
}
public void setYears(String Years)
{
year = Years;
}
public String getColor()
{
return color;
}
public void setColor(String Colors)
{
color = Colors;
}
public double getPrice()
{
return price;
}
public void setPrice(double Prices)
{
price = Prices;
}
public Makes getMakes()
{
return make;
}
public void setMakes(String nCountry, String nManufac, String nBrand)
{
String country = nCountry;
String manufacturer = nManufac;
String nameBrand = nBrand;
}
public String toString()
{
String result;
result = "Year:\t\t" + year + "\n" + "Color:\t\t" + color + "\n" + "Price:\t\t" + price + "\n\n";
return result;
}
}
OVERALL: both my car class and makes class are compiling. I am receiving this error when I try to compile the assignment 4 part:
cannot find symbol:
car1.setYear(year);
any input would be greatly appreciated.