All pastes #386328 Raw Edit

MarkManagF

public java v1 · immutable
·published 2007-03-08 14:54 UTC
rendered paste body
/** * @(#)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 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<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++){			tempArray[k].displayInfo();		}*/		//Add in Rearranging Code for ArrayList		for (int i=0;i <studentTracker.size();i++){			studentTracker.set(i,tempArray[i]);					}				}public static void newStudent () throws IOException {	String nameFirst, nameLast;	int numberStudent=0;	boolean satisfaction=false;	boolean bit8Correction=false;	String temp2="";		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;			}			}				}	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<studentTracker.size(); i++){		tempReader = studentTracker.get(i);		System.out.println(i+". "+tempReader.showLastName()+", "+tempReader.showFirstName() );	}	System.out.println("\n Make Report- \n 1.Individual Report \n 2.Class Report \n 3.Back ");	selectedMode=choice(selectedMode,3);	  		switch(selectedMode){				case(1):					choice=compareInput();					System.out.println("Loading Data For Student"+choice);					if (choice >=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<studentTracker.size();i++){						tempReader = studentTracker.get(i);						if (tempNumber == tempReader.showNumber()){							return i;													}					}			}else{				tempNumber = Integer.parseInt(temp);				if (tempNumber >= 0 & tempNumber <= studentTracker.size()){					 					return tempNumber;				}						}					}else {			//ITS A STRING PASTA			System.out.println("I RECOGNIZE THIS AS STRING");			for (int i=0;i<studentTracker.size();i++){				tempReader = studentTracker.get(i);				if(temp.toLowerCase().indexOf(tempReader.showLastName().toLowerCase()) >= 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. :)");    		}    	}    	    }        }