Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.63 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class Admin {
  4.     // create an instance of Enrolment
  5.     Enrolment enrolement = new Enrolment();
  6.  
  7.     public static void main(String[] args) throws IOException {
  8.         String i = "=====================";
  9.         System.out.println(i);
  10.         System.out.println("Student Admin System");
  11.         System.out.println(i);
  12.         System.out.print("Creating Enrolment...");
  13.         // create instance of Admin which creates an instance of Enrolment
  14.         Admin admin = new Admin();
  15.         System.out.println("Done");
  16.         System.out.print("Populating Enrolment...");
  17.         // send method calls to the instance of Admin (admin) to access non
  18.         // static methods
  19.         admin.fillData();
  20.         admin.searchStudent();
  21.     }
  22.  
  23.     // Creates an enrolment list using the addStudent() method
  24.     // Prints the details of the student using the printEnrolment() method
  25.     public void fillData() {
  26.        
  27.         enrolement.addStudent(1, "John", "Smith", "Male", "1985-02-11",
  28.                                 "0413 454 556", 1995);
  29.         enrolement.addStudent(23456789, "David", "Nguyen", "female",
  30.                                 "2007 05 25", "(03) 9311 3204", 2006);
  31.         enrolement.addStudent(34567890, "Michael", "googlestien", "f",
  32.                                 "20050601", "03-9364-8745", 1998);
  33.         enrolement.addStudent(45678901, "Paul", "sinartra", "M", "19910416",
  34.                                 "0400101987", 2006);
  35.         enrolement.addStudent(99999999, "Jesus", "ciaffaglione", "F",
  36.                                 "1963/01/18", "98754684", 2004);
  37.         System.out.println("Done" + "\n");
  38.         System.out.println("The current students in the enrolment list are:"
  39.                 + "\n");
  40.         enrolement.printEnrolment();
  41.     }
  42.  
  43.     // Asks user for a commencement year and prints all Students with the same
  44.     // commencement year using printDetails()
  45.     public void searchStudent() throws IOException {
  46.         // searchStudent variables
  47.         String j = "=============================================";
  48.         boolean fail = true;
  49.         BufferedReader searchInput = new BufferedReader(new InputStreamReader(
  50.                 System.in));
  51.  
  52.         // ask for input on the console
  53.         System.out.println(j);
  54.         System.out.println("Please enter a commencing year to search for:");
  55.         int year = Integer.parseInt(searchInput.readLine());
  56.  
  57.         // determines if there are any matching Students using a boolean
  58.         for (int i = 0; i < enrolement.getMaxStudents(); i++) {
  59.             if (enrolement.getStudent(i) != null
  60.                     && enrolement.getStudent(i).getYear() == year) {
  61.                 fail = false;
  62.             }
  63.         }
  64.         // executed when there is matching students
  65.         if (fail == false) {
  66.             System.out.println("\n" + "The following students commenced in "
  67.                     + year + ":" + "\n");
  68.             for (int i = 0; i < enrolement.getMaxStudents(); i++) {
  69.                 // if the enrolment index is not empty and there is a matching
  70.                 // Student use printDetails to print to console
  71.                 if (enrolement.getStudent(i) != null
  72.                         && enrolement.getStudent(i).getYear() == year) {
  73.                     System.out.println(enrolement.getStudent(i).printDetails());
  74.                 }
  75.             }
  76.             // executed when there is no matching students
  77.         } else if (fail == true) {
  78.             System.out.println("\n"
  79.                     + "Sorry, no students in the enrolment list.");
  80.             searchStudent();
  81.         }
  82.  
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement