Posted By

cetnar on 07/15/06


Tagged

tiger enum


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

xaviaracil
LarryStreeter


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.