// Program to use Java Enum as a Class type.
enum Colour
{
Red(200), Green(150), Blue(100), Black(250), White(175), Orange(225), Yellow(125);
private int price; // price of each colour
Colour(int p)
{
price = p;
}
int getPrice()
{
return price;
}
}class EnumDemo3
{
public static void main(String args[ ])
{
Colour c1;
// Display price of Green.
System.out.println("Green costs " + Colour.Green.getPrice() + " Rs.");// Display all colours and prices.
System.out.println("All Colour's prices: ");
for(Colour c : Colour.values())
System.out.println(c + " costs " + c.getPrice() + " Rs.");
}
}
Output:Green costs 150 Rs.
All Colour's prices:
Red costs 200 Rs.
Green costs 150 Rs.
Blue costs 100 Rs.
Black costs 250 Rs.
White costs 175 Rs.
Orange costs 225 Rs.
Yellow costs 125 Rs.