Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class Admin {
- // create an instance of Enrolment
- Enrolment enrolement = new Enrolment();
- public static void main(String[] args) throws IOException {
- String i = "=====================";
- System.out.println(i);
- System.out.println("Student Admin System");
- System.out.println(i);
- System.out.print("Creating Enrolment...");
- // create instance of Admin which creates an instance of Enrolment
- Admin admin = new Admin();
- System.out.println("Done");
- System.out.print("Populating Enrolment...");
- // send method calls to the instance of Admin (admin) to access non
- // static methods
- admin.fillData();
- admin.searchStudent();
- }
- // Creates an enrolment list using the addStudent() method
- // Prints the details of the student using the printEnrolment() method
- public void fillData() {
- enrolement.addStudent(1, "John", "Smith", "Male", "1985-02-11",
- "0413 454 556", 1995);
- enrolement.addStudent(23456789, "David", "Nguyen", "female",
- "2007 05 25", "(03) 9311 3204", 2006);
- enrolement.addStudent(34567890, "Michael", "googlestien", "f",
- "20050601", "03-9364-8745", 1998);
- enrolement.addStudent(45678901, "Paul", "sinartra", "M", "19910416",
- "0400101987", 2006);
- enrolement.addStudent(99999999, "Jesus", "ciaffaglione", "F",
- "1963/01/18", "98754684", 2004);
- System.out.println("Done" + "\n");
- System.out.println("The current students in the enrolment list are:"
- + "\n");
- enrolement.printEnrolment();
- }
- // Asks user for a commencement year and prints all Students with the same
- // commencement year using printDetails()
- public void searchStudent() throws IOException {
- // searchStudent variables
- String j = "=============================================";
- boolean fail = true;
- BufferedReader searchInput = new BufferedReader(new InputStreamReader(
- System.in));
- // ask for input on the console
- System.out.println(j);
- System.out.println("Please enter a commencing year to search for:");
- int year = Integer.parseInt(searchInput.readLine());
- // determines if there are any matching Students using a boolean
- for (int i = 0; i < enrolement.getMaxStudents(); i++) {
- if (enrolement.getStudent(i) != null
- && enrolement.getStudent(i).getYear() == year) {
- fail = false;
- }
- }
- // executed when there is matching students
- if (fail == false) {
- System.out.println("\n" + "The following students commenced in "
- + year + ":" + "\n");
- for (int i = 0; i < enrolement.getMaxStudents(); i++) {
- // if the enrolment index is not empty and there is a matching
- // Student use printDetails to print to console
- if (enrolement.getStudent(i) != null
- && enrolement.getStudent(i).getYear() == year) {
- System.out.println(enrolement.getStudent(i).printDetails());
- }
- }
- // executed when there is no matching students
- } else if (fail == true) {
- System.out.println("\n"
- + "Sorry, no students in the enrolment list.");
- searchStudent();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement