Posted By

cetnar on 07/15/06


Tagged

tiger Switch enum


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

xaviaracil


Switching on enums


 / Published in: Java
 

  • Tiger simply requires that you not preface each enumerated type with the enum class name
  • if not handling every enumerated type - warining will be displayed that not all of enum values not being compile time constants
  1. public void testSwitchStatement(PrintStream out) throws IOException {
  2.  
  3. StringBuffer outputText = new StringBuffer(student1.getFullName( ));
  4.  
  5.  
  6.  
  7. switch (student1.getGrade( )) {
  8.  
  9. case A:
  10.  
  11. outputText.append(" excelled with a grade of A");
  12.  
  13. break;
  14.  
  15. case B: // fall through to C
  16.  
  17. case C:
  18.  
  19. outputText.append(" passed with a grade of ")
  20.  
  21. .append(student1.getGrade( ).toString( ));
  22.  
  23. break;
  24.  
  25. case D: // fall through to F
  26.  
  27. case F:
  28.  
  29. outputText.append(" failed with a grade of ")
  30.  
  31. .append(student1.getGrade( ).toString( ));
  32.  
  33. break;
  34.  
  35. case INCOMPLETE:
  36.  
  37. outputText.append(" did not complete the class.");
  38.  
  39. break;
  40.  
  41. }
  42.  
  43.  
  44.  
  45. out.println(outputText.toString( ));
  46.  
  47. }

Report this snippet  

You need to login to post a comment.