/** * @(#)markmanager.java * * * @author mike C * @version 1.00 2007/2/26 */import java.io.*;import java.util.Arrays;import java.util.ArrayList;public class marksManager {static int selectedMode=0;static ArrayList<student> studentTracker = new ArrayList<student>();/* selectedMode Mode Reference-0.On Main Menu1.Create New Student2.Edit Student information3.Overview4.Exit Program :(*/private static void mainMenu () { System.out.println("\n Manage Marks and Stuff- \n 1.New Student \n 2.Edit Student \n 3.Overview \n 4.Exit Program");}public static void alphaSort(){ char[] name1, name2; String nam1,nam2; student placeHolder; student[] tempArray = new student[studentTracker.size()]; for(int i=0;i<studentTracker.size();i++){ tempArray[i] = studentTracker.get(i); //tempArray[i].displayInfo(); } for (int g=0;g<tempArray.length;g++){ for (int i=0;i<tempArray.length-1;i++){//Two Student Compare nam1 =tempArray[i].showLastName().toLowerCase(); nam2 =tempArray[i+1].showLastName().toLowerCase(); name1 =nam1.toCharArray(); name2 =nam2.toCharArray(); //System.out.println(tempArray[i].showLastName()+", "+tempArray[i].showFirstName()+" comparing with "+tempArray[i+1].showLastName()+", "+tempArray[i+1].showFirstName() ); if (nam1.toLowerCase().indexOf(nam2.toLowerCase() ) >= 0){// Check For the same last name, if true compares first names. //System.out.println(tempArray[i].showLastName()+", "+tempArray[i].showFirstName()+" has the same last name as "+tempArray[i+1].showLastName()+", "+tempArray[i+1].showFirstName() ); nam1= tempArray[i].showFirstName().toLowerCase(); nam2= tempArray[i+1].showFirstName().toLowerCase(); name1 = nam1.toCharArray(); name2 = nam2.toCharArray(); } for (int j=0;j <= name1.length;j++){ if (name1[j] > name2[j]){ //System.out.println(tempArray[i].showLastName()+", "+tempArray[i].showFirstName()+" goes behind "+tempArray[i+1].showLastName()+", "+tempArray[i+1].showFirstName() ); placeHolder=tempArray[i]; tempArray[i]=tempArray[i+1]; tempArray[i+1]=placeHolder; break; } else { if (name1[j] < name2[j]){ //System.out.println(tempArray[i].showLastName()+", "+tempArray[i].showFirstName()+" is in proper position between "+tempArray[i+1].showLastName()+", "+tempArray[i+1].showFirstName() ); break; } } } } } /*for (int k=0;k<tempArray.length;k++){ alphaSort(); tempArray[k].displayInfo(); }*/ //Add in Rearranging Code for ArrayList}public static void newStudent () throws IOException { String nameFirst, nameLast; int numberStudent=0; boolean satisfaction=false; boolean bit8Correction=false; String temp2=""; student tempReader; BufferedReader getIN = new BufferedReader (new InputStreamReader (System.in)); while (satisfaction == false){ for (int i1=0;;i1++){//Input student information. System.out.println("Please enter the student's last name."); nameLast = getIN.readLine(); System.out.println("Please enter the student's first name."); nameFirst = getIN.readLine(); while (bit8Correction==false){ // Loop to make sure that number entered is 8 digits. System.out.println("Please enter the student's number."); temp2 = getIN.readLine(); numberStudent =Integer.parseInt(temp2); if (temp2.length()==8){ bit8Correction=true; } }//Check if the data is correct. System.out.println("Student Information is as follows: "+nameLast+", "+nameFirst+"\n Number: "+numberStudent); System.out.println("Is this correct?"); temp2 = getIN.readLine(); if (temp2.indexOf("y")>=0 || temp2.indexOf("Y")>=0){ // If satisfied with input create a new student (create a temp array, then make the main equal to the temp) satisfaction = true; studentTracker.add(studentTracker.size(),new student(nameLast,nameFirst,numberStudent)); break; } } } System.out.println("Back to Main Menu."); }public static void editStudent () throws IOException { // 1. Change Student Information, 2. Add Marks, 3. Edit Marks // Show class then take either a name or a student number System.out.println("\n Manage Student Information- \n 1.Change Student Information \n 2.Add Marks \n 3.Edit Marks "); selectedMode=choice(selectedMode,3); switch(selectedMode){ case(1): System.out.println("CHANGE STUDENT INFO"); break; case(2): System.out.println("ADD MARKS"); break; case(3): System.out.println("EDIT MARKS"); break; default: System.out.println("Back to main menu."); }}public static void overView () throws IOException { // Show Individual Marks, or Show Class Marks System.out.println("There are currently "+studentTracker.size()+" students being accounted for."); for (int i=0; studentTracker.size() >i ; i++){ studentTracker.get(i).displayInfo(); } }public static void deleteStudent () throws IOException {}public static int choice (int currentSel, int upperBounds) throws IOException {BufferedReader getIN = new BufferedReader (new InputStreamReader (System.in)); for (int inf=0;;inf++){ for (int inf2=0;;inf2++){ String temp = getIN.readLine(); int i = Integer.parseInt(temp); if (i <= upperBounds & i >= 1){ System.out.println("Acceptable"); return i; }else{ System.out.println("Sorry, that's not a valid option."); break; } } } }public static void main(String[] args) throws IOException { boolean letMeOut = false; while (letMeOut == false){ mainMenu(); selectedMode=choice(selectedMode, 4); switch(selectedMode){ case(1): newStudent (); break; case(2): System.out.println("There are "+studentTracker.size()+" unique students, being tracked."); editStudent(); break; case(3): overView(); break; case(4): letMeOut=true; default: //mainMenu(); System.out.println("Thanks for using this useless program, all your hard work in data input is now being deleted. \n Have a nice day. :)"); } } } }