Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package assignment.pkg2;
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author Ray
- */
- import java.util.GregorianCalendar;
- public class Enrolment {
- final int MAX_STUDENTS = 5;
- Student[] studentArray;
- //public int getMaxStudents() {
- // return this.MAX_STUDENTS;
- //}
- public void Enrolment() {
- studentArray = new Student[MAX_STUDENTS];
- }
- //enrolment.addStudent(33456789, "Judy", "Smith", "Female",
- // new GregorianCalendar(1983, 7, 23), "0398876543", 2008);
- public boolean addStudent(int studentNumber, String firstName,
- String lastName, String gender, GregorianCalendar dateOfBirth,
- String phoneNumber, int startYear) {
- /* for loop used to ensure each index is checked before adding new
- * student
- */
- System.out.println("omg");
- for (int i = 0; i < MAX_STUDENTS -1; i++) {
- /* This if statement is necessary to check that the paricular index
- * is empty to avoid accidentally writting over other students
- * details
- */
- System.out.println("omga");
- if (studentArray[i] == null) {
- System.out.println("omgb");
- /* This creates a new student object which will contain the
- * relevant details; student number, first name...etc
- */
- studentArray[i] = new Student(studentNumber, firstName, lastName,
- gender, dateOfBirth, phoneNumber, startYear);
- System.out.println("omgc");
- return true;
- }
- }
- //if the studentArray is full return false
- return false;
- }
- /* This method returns a particular student based on its index in
- * studentArray
- */
- public Student getStudent(int index) {
- return studentArray[index];
- }
- /* This method is used to print the Students details via the printDetails
- * method
- */
- public void printEnrolment() {
- for (int i = 0; i <= MAX_STUDENTS; i++) {
- //Used to ensure that empty indexes are not printed
- if (studentArray[i] != null) {
- //prints the students details using the printDetails method
- System.out.println(studentArray[i].printDetails());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement