I was following our teachers instructions but even still the program runs into a problem where it says that both CONVERTABLE and BLACK cannot be resolved or is not a field.
public class CarDemo {
public static void main(String[] args) {
Car car1 = new Car(2014, Model.CONVERTABLE, Color.BLACK);
}
class Car{
private int year;
private Model model;
private Color color;
public Car(int yr, Model model, Color color){
year = yr;
this.model = model;
this.color = color;
}
public void display(){
System.out.println(year);
System.out.println(model);
System.out.println(color);
}
}
class Model{
enum model {SEDAN, SUV, CONVERTABLE, HATCHBACK;}
}
class Color{
enum color {RED, BLUE, VIOLET, PINK, BLACK, WHITE;}
} }
Another version of the code when trying to fix the code was this
public class CarDemo {
public static void main(String[] args) {
Car car1 = new Car(2014, Model.model.CONVERTABLE, Color.color.BLACK);
}
class Car{
private int year;
private CarDemo.Model.model model;
private CarDemo.Color.color color;
public Car(int yr, CarDemo.Model.model m, CarDemo.Color.color c){
year = yr;
model = m;
color = c;
}
public void display(){
System.out.println(year);
System.out.println(model);
System.out.println(color);
}
}
class Model{
enum model {SEDAN, SUV, CONVERTABLE, HATCHBACK;}
}
class Color{
enum color {RED, BLUE, VIOLET, PINK, BLACK, WHITE;}
} }
but still didn't work and a new error came out it said No enclosing instance of type CarDemo is accessible