We Recommend

Java How to Program Java How to Program
Takes a new tools-based approach to Web application development that uses Netbeans 5.5 and Java Studio Creator 2 to create and consume Web Services. Features new AJAX-enabled, Web applications built with JavaServer Faces (JSF), Java Studio Creator 2 and the Java Blueprints AJAX Components. Includes new topics throughout, such as JDBC 4, SwingWorker for multithreaded GUIs, GroupLayout, Java Desktop Integration Components (JDIC), and much more.


Posted By

cetnar on 07/15/06


Tagged

tiger enum


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

xaviaracil


Using Enum


Published in: Java 


  1. public enum Grade { A, B, C, D, F, INCOMPLETE };
  2.  
  3. public class Student {
  4.  
  5.  
  6.  
  7. private String firstName;
  8.  
  9. private String lastName;
  10.  
  11. private Grade grade;
  12.  
  13.  
  14.  
  15. public Student(String firstName, String lastName) {
  16.  
  17. this.firstName = firstName;
  18.  
  19. this.lastName = lastName;
  20.  
  21. }
  22.  
  23. .....
  24.  
  25. public void assignGrade(Grade grade) {
  26.  
  27. this.grade = grade;
  28.  
  29. }
  30.  
  31.  
  32.  
  33. public Grade getGrade( ) {
  34.  
  35. return grade;
  36.  
  37. }
  38.  
  39. }
  40.  
  41.  
  42.  
  43. public void testGradeAssignment(PrintStream out) throws IOException {
  44.  
  45. Student student1 = new Student("Brett", "McLaughlin");
  46.  
  47. Student student2 = new Student("Ben", "Rochester");
  48.  
  49. Student student3 = new Student("Dennis", "Erwin");
  50.  
  51.  
  52.  
  53. student1.assignGrade(Grade.B);
  54.  
  55. student2.assignGrade(Grade.INCOMPLETE);
  56. student3.assignGrade(Grade.A);
  57.  
  58. }

Report this snippet 

You need to login to post a comment.