java add constructor to enum

Solutions on MaxInterview for java add constructor to enum by the best coders in the world

showing results for - "java add constructor to enum"
Océane
03 Aug 2017
1package cakes;
2
3public class EnumDemo {
4
5	public enum Food {
6		HAMBURGER(7), FRIES(2), HOTDOG(3), ARTICHOKE(4);
7
8		Food(int price) {
9			this.price = price;
10		}
11
12		private final int price;
13
14		public int getPrice() {
15			return price;
16		}
17	}
18
19	public static void main(String[] args) {
20		for (Food f : Food.values()) {
21			System.out.print("Food: " + f + ", ");
22
23			if (f.getPrice() >= 4) {
24				System.out.print("Expensive, ");
25			} else {
26				System.out.print("Affordable, ");
27			}
28
29			switch (f) {
30			case HAMBURGER:
31				System.out.println("Tasty");
32				continue;
33			case ARTICHOKE:
34				System.out.println("Delicious");
35				continue;
36			default:
37				System.out.println("OK");
38			}
39		}
40
41	}
42
43}