Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. package assignment.pkg2;
  2. /*
  3. * To change this template, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. /**
  8. *
  9. * @author Ray
  10. */
  11. import java.util.GregorianCalendar;
  12.  
  13. public class Enrolment {
  14.  
  15. final int MAX_STUDENTS = 5;
  16. Student[] studentArray;
  17.  
  18. //public int getMaxStudents() {
  19. // return this.MAX_STUDENTS;
  20. //}
  21.  
  22. public void Enrolment() {
  23. studentArray = new Student[MAX_STUDENTS];
  24. }
  25. //enrolment.addStudent(33456789, "Judy", "Smith", "Female",
  26. // new GregorianCalendar(1983, 7, 23), "0398876543", 2008);
  27. public boolean addStudent(int studentNumber, String firstName,
  28. String lastName, String gender, GregorianCalendar dateOfBirth,
  29. String phoneNumber, int startYear) {
  30. /* for loop used to ensure each index is checked before adding new
  31. * student
  32. */
  33. System.out.println("omg");
  34. for (int i = 0; i < MAX_STUDENTS -1; i++) {
  35.  
  36. /* This if statement is necessary to check that the paricular index
  37. * is empty to avoid accidentally writting over other students
  38. * details
  39. */
  40. System.out.println("omga");
  41. if (studentArray[i] == null) {
  42. System.out.println("omgb");
  43. /* This creates a new student object which will contain the
  44. * relevant details; student number, first name...etc
  45. */
  46. studentArray[i] = new Student(studentNumber, firstName, lastName,
  47. gender, dateOfBirth, phoneNumber, startYear);
  48. System.out.println("omgc");
  49. return true;
  50. }
  51.  
  52. }
  53.  
  54.  
  55. //if the studentArray is full return false
  56. return false;
  57. }
  58.  
  59. /* This method returns a particular student based on its index in
  60. * studentArray
  61. */
  62. public Student getStudent(int index) {
  63. return studentArray[index];
  64. }
  65.  
  66. /* This method is used to print the Students details via the printDetails
  67. * method
  68. */
  69. public void printEnrolment() {
  70. for (int i = 0; i <= MAX_STUDENTS; i++) {
  71. //Used to ensure that empty indexes are not printed
  72. if (studentArray[i] != null) {
  73. //prints the students details using the printDetails method
  74. System.out.println(studentArray[i].printDetails());
  75. }
  76. }
  77.  
  78.  
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement