CS202 OOP Final Project
CS202 OOP Final Project
Final Project
Tran Van Loc 10ES
public class StudentManagement { /*Use to contain the list of students*/ Vector list =new Vector(); public StudentManagement() { while(true) { /*Show the Menu in the Program*/ System.out.println("Programme of Student Management"); System.out.println("Options of the Programme"); System.out.println("1.Type the new Student List"); System.out.println("2.Show the Student List"); System.out.println("3.Arrange the Student List from the lowest to the highest"); System.out.println("4.Find Student by Name"); System.out.println("5.Quit"); System.out.println("======================================="); /*Type one number from the Keyboard*/ int num; Scanner keyboard = new Scanner(System.in); System.out.print("Please Enter a number to Choose: "); num = keyboard.nextInt(); /*Check and call the appropriate chosen*/ switch (num) { case 1: this.input(); break; case 2: this.view(); break; case 3: sort(); break; case 4: search(); break; case 5: System.out.print("Programme's End"); return; } } } /*Type the Student List*/
public void input() { /*Enter the Number of Student in List*/ int num; Scanner keyboard = new Scanner(System.in); System.out.print("Enter the Number of Student : "); num = keyboard.nextInt(); /*Enter the Information for Each Student*/ for (int i=1; i<=num;i++) { System.out.println("Enter the Students Information: "+i); System.out.print(" ID : "); int id = Integer.parseInt(keyboard.next()); keyboard.nextLine();//clear cache System.out.print(" Name : "); String name = keyboard.nextLine(); System.out.print(" GPA : "); double aver = keyboard.nextDouble(); /*Creat the Student Object, after input the Information*/ Student st = new Student(id, name, aver); /*Save Student Object to the List*/ list.add(st); } System.out.println("\n==========\n"); }
/*View the Student List*/ public void view() { /*Show the Student List*/ System.out.println(" List of Student and Information"); /*Take Student from the List (vector) and store in vEnum*/ Enumeration vEnum = list.elements(); /*Check every element of vEnum*/ int i=1; /**/ while(vEnum.hasMoreElements()) { /*Lay phan tu tu vEnum ep lai kieu Student*/ Student sts = (Student)vEnum.nextElement(); /*Show Student Information*/ System.out.println(" "+i+" . ID="+sts.getId()+", Name= "+sts.getName()+", GPA="+sts.getAver()); i++; } System.out.println("\n==========\n"); }
/*Arrange the Student List from the lowest to the highest GPA using sort() function and class Arrays*/ public void sort() { /*Do? du lieu tu Vector vao mang? de goi ham sort sap xep mang*/ Student[] sts = new Student[list.size()]; int index=0; Enumeration vEnum = list.elements(); while(vEnum.hasMoreElements()) { sts[index] = (Student)vEnum.nextElement(); index++; } /*Arrange Arrays*/ Arrays.sort(sts); System.out.println("\n--List of Student after Arranging--"); for(index=0; index < sts.length; index++) { /*Show the Students Information after arranging*/ System.out.println(" "+(index+1)+" .ID= "+sts[index].getId()+" , Name= "+sts[index].getName()+" , GPA="+sts[index].getAver()); } System.out.println("\n==========\n"); } /*Search Student by Name*/ public void search() { /*Enter Name of Student that needs to find*/ Scanner keyboard = new Scanner(System.in); System.out.print("Enter Name of Student that needs to find"); String name = keyboard.nextLine(); /*Check every element of array to compare with Finding Name*/ Enumeration vEnum = list.elements(); System.out.println("\n--Searching Result--"); while(vEnum.hasMoreElements()) { Student sts = (Student)vEnum.nextElement(); /*Neu ten sv chua' chuoi~ nhap vao thi hien thi thong tin doi tuong sinh vien*/ if(sts.getName().indexOf(name)!=-1) System.out.println("ID= "+sts.getId()+", Name="+sts.getName()+", GPA= "+sts.getAver()); } System.out.println("\n==========\n"); }
public static void main(String[] args) { // Construct the Programme //StudentManagement sm = new StudentManagement();
//create a new instance /* DecimalFormat format=DecimalFormat.getInstance(); DecimalFormatSymbols symbols=format.getDecimalFormatSymbols(); char sep=symbols.getDecimalSeparator(); DecimalFormatSymbols custom=new DecimalFormatSymbols(); custom.setDecimalSeparator(','); format.setDecimalFormatSymbols(custom);*/ } } /*Build Class Student to implement "interface Comparable", define compareTo function * to serve arranging */