-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnumTest.java
36 lines (30 loc) · 957 Bytes
/
EnumTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package enums;
import java.util.Scanner;
enum Size {
SMALL("S"), MEDIUM("M"), LARGE("L"), EXTRA_LARGE("XL");
private final String abbreviation;
Size(String abbreviation) {
this.abbreviation = abbreviation;
}
public String getAbbreviation() {
return abbreviation;
}
}
/**
* This program demonstrates enumerated types.
*
* @author Cay Horstmann
* @version 1.0 2004-05-24
*/
public class EnumTest {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a size: (SMALL, MEDIUM, LARGE, EXTRA_LARGE) ");
String input = in.next().toUpperCase();
Size size = Enum.valueOf(Size.class, input);
System.out.println("size = " + size);
System.out.println("abbreviation = " + size.getAbbreviation());
if (size == Size.EXTRA_LARGE)
System.out.println("Good job--you paid attention to the _.");
}
}