/** * @(#)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 studentTracker = new ArrayList(); /* selectedMode Mode Reference- 0.On Main Menu 1.Create New Student 2.Edit Student information 3.Overview 4.Exit Program :( */ private static void mainMenu () { System.out.println("\n Manage Marks and Stuff- \n 1.New Student \n 2.Edit Information \n 3.Mark Reports \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= 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=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; } } } alphaSort(); 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 \n 4.Back "); selectedMode=choice(selectedMode,4); 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; case(4): break; default: System.out.println("Back to main menu."); } } public static void overView () throws IOException { // Show Individual Marks, or Show Class Marks student tempReader; int choice; System.out.println("There are currently "+studentTracker.size()+" students being accounted for."); for (int i=0; i=0){ tempReader=studentTracker.get(choice); tempReader.displayAll(); } break; case(2): for (int i=0; studentTracker.size() >i ; i++){ tempReader=studentTracker.get(i); tempReader.displayAll(); } break; case(3): break; default: System.out.println("Back to main menu."); } } 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 int compareInput() throws IOException { BufferedReader getIN = new BufferedReader (new InputStreamReader (System.in)); student tempReader; String temp = getIN.readLine(); char[] temp2 = temp.toCharArray(); for(int k=0; k < temp2.length; k++) if ( (int)temp2[k] <=48 & (int)temp2[k]>= 57){ //THEN A CHAR IS AN INT AND YOU WILL EAT SUSHI System.out.println("I RECOGNIZE THIS AS INTEGER"); int tempNumber; if (temp.length() == 8){ //Check for student number tempNumber = Integer.parseInt(temp); for (int i=0;i= 0 & tempNumber <= studentTracker.size()){ return tempNumber; } } }else { //ITS A STRING PASTA System.out.println("I RECOGNIZE THIS AS STRING"); for (int i=0;i= 0){ return i;// Last Name was put }else{ if(temp.toLowerCase().indexOf(tempReader.showFirstName().toLowerCase()) >= 0){ return i; // First Name was put } } } } return -1;// You fail even after getting 4 input choices. } public static void main(String[] args) throws IOException { boolean letMeOut = false; studentTracker.add(0,new student("Cecconet","Michael",66622666)); studentTracker.add(1,new student("Cecconet", "Dopelganger", 12943413)); studentTracker.add(2,new student("Tennocec", "Leahcim", 31434921)); studentTracker.add(3,new student("Simon", "Joshua", 23443413)); studentTracker.add(4,new student("Defilipis", "Joe", 24523417)); studentTracker.add(5,new student("Caia", "Gaspare", 32424123)); studentTracker.add(6,new student("Test", "Test", 22222222)); studentTracker.add(7,new student("Kitty", "Hello", 24234234)); studentTracker.add(8,new student("Rocketfingers", "Johnny", 32424123)); studentTracker.add(9,new student("Salad", "Tasty", 24324243)); studentTracker.add(10,new student("Seafood", "Fresh", 86846354)); studentTracker.add(11,new student("Pasta", "Steaming", 34324676)); alphaSort(); 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. :)"); } } } }