/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication3; import java.util.*; public class TestStudent { static Scanner input = new Scanner(System.in); static Student[] stuArray = new Student[114]; static int count = 0; public static void main(String[] args) { // TODO code application logic here int choice = 0; do { System.out.println("Student Registration System\n"); System.out.println("1 - Add Student\n"); System.out.println("2 - Search by matric no\n"); System.out.println("3 - Display all\n"); System.out.println("4 - Exit\n"); System.out.println("Please enter your choice\n"); choice = input.nextInt(); switch (choice) { case 1: NewStudent(); break; case 2: SearchByMatric(); break; case 3: DisplayAll(); break; case 4: System.out.println("Good bye"); } } while (choice != 4); } public static void NewStudent() { System.out.println("Add New Student\n"); System.out.println("Enter first name: \n"); String f = input.next(); System.out.println("Enter last name: \n"); String la = input.next(); System.out.println("Enter matric no: \n"); String m = input.next(); System.out.println("Enter age: \n"); int age = input.nextInt(); stuArray[count] = new Student(f, la, m, age); count++; } public static void DisplayAll() { for (int i = 0; i < count; i++) { System.out.println(stuArray[i]); } } public static void SearchByMatric() { System.out.println("Search by matric no\n"); System.out.println("Enter matric no: \n"); String m = input.next(); boolean found =false; int i; for (i = 0; i < count; i++) { if (m.equalsIgnoreCase(stuArray[i].getMatricNo())) { found = true; break; } } if (found) System.out.println(stuArray[i]); else System.out.println("cannot find the student with matric no " + m); } }