enum Problem {
// 8, 10 & 16 are passed to the constructor
BIG(8), HUGE(10), SMALL(16);
Problem(int ounces) { // constructor
this.ounces = ounces;
}
private int ounces;
public int getOunces() {
return ounces;
}
}
class MyClass {
Problem size;
public static void main(String[] args) {
MyClass drink1 = new MyClass();
drink1.size = Problem.BIG;
MyClass drink2 = new MyClass();
drink2.size = Problem.SMALL;
System.out.println(drink1.size.getOunces());
for(Problem cs: Problem.values())
System.out.println(cs + " " + cs.getOunces());
}
}
|