Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. package Dzial_5;
  2.  
  3. import java.util.*;
  4.  
  5. public class EnumTest
  6. {
  7.  
  8. public static void main(String[] args)
  9. {
  10. Scanner in = new Scanner(System.in);
  11. System.out.print("Enter a size: (SMALL, MEDIUM, LARGE, EXTRA_LARGE) ");
  12. String input = in.next().toUpperCase();
  13. Size size = Enum.valueOf(Size.class, input);
  14. System.out.println("size=" + size);
  15. System.out.println("abbreviation=" + size.getAbbreviation());
  16. if (size == Size.EXTRA_LARGE)
  17. {
  18. System.out.println("Good job--you paid attention to the _.");
  19. }
  20.  
  21. in.close();
  22.  
  23. }
  24. }
  25.  
  26.  
  27. enum Size
  28. {
  29. SMALL("S"), MEDIUM("M"), LARGE("L"), EXTRA_LARGE("XL");
  30.  
  31. private Size(String abbreviation)
  32. {
  33. this.abbreviation = abbreviation;
  34. }
  35.  
  36. public String getAbbreviation()
  37. {
  38. return abbreviation;
  39. }
  40.  
  41. private String abbreviation;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement