All pastes #403494 Raw Edit

nig

public text v1 · immutable
·published 2007-03-20 12:47 UTC
rendered paste body
/**
 * @(#)marksManager.java
 *
 * marksManager application
 *
 * @author 
 * @version 1.00 2007/2/26
 */
import java.util.*;
public class marksManager {
    static boolean match1 = false;
    static boolean match2 = false;
    static boolean checking = true;
    static boolean checkLength = true;
    static boolean checkMark1 = true;
    static boolean checkMark2 = true;
    static boolean checkMark3 = true;
    static boolean checkMark4 = true;
    static boolean checkMark5 = true;
    static boolean checkNames = true;  
    static int spot;
    static boolean menu = true;
    static boolean complete1 = false;
    static boolean complete2 = false;
    static boolean complete3 = false;
    static boolean complete4 = false;
    static boolean complete5 = false;
    static boolean complete6 = false;
    static int answer = 0;
    static int amount = 0;
    static String[] names = new String[100];
    static String[] newNames = new String[100];
    static int[] numbs = new int[100];
    static int[] total = new int[5];
    static int[] marks1 = new int[5];
    static int[] marks2 = new int[5];
    static int[] marks3 = new int[5];
    static int[] marks4 = new int[5];
    static int[] marks5 = new int[5];
    static int nums = 0;
    public static void main(String[] args) {
    	
    //Begins the while menu
    
    while (menu == true){
    
    System.out.println("What would you like to do?");
    System.out.println("1 - Input Student Names");
    System.out.println("2 - Input Student Numbers");
    System.out.println("3 - Input Student Marks");
    System.out.println("4 - Give Individual Student Reports");
    System.out.println("5 - Give Class Report");
    System.out.println("6 - Add/Remove Student");
    System.out.println("7 - Exit Program");
    Scanner menuSpot = new Scanner(System.in);
    answer = menuSpot.nextInt();
    if (answer == 7){
    	break;
    }
    if (answer > 7){
    	System.out.println("Incorrect choice option. Re-input option.");
    }
    if (answer == 1){
    // Gets number of students
    System.out.println ("How many students are you entering?");
    Scanner getNumber = new Scanner(System.in);
    amount = getNumber.nextInt(); 	
    
    // Get Names 
    
    String[] names =new String[amount];
    for (int i = 0; i < amount; i ++){
    	System.out.print ("Input the full name of student " +(i+1) + " in the following format: Last name, First Name.");
    	Scanner takeName = new Scanner(System.in);
    	names[i] = takeName.nextLine();	
    	while (checkNames == true){
    		int goodName = names[i].indexOf(", ");
    		if (goodName == -1){
    			System.out.println ("Incorrect student name format. Please re-input student name for student "+(i+1) + ".");
    			Scanner fixName = new Scanner(System.in);
    			names[i] = fixName.nextLine();
    		}
    		else if (goodName != -1){
    			checkNames = false;
    		}
    	}
    	if (checkNames == false && i == amount-1){
    		break;
    	}
    	checkNames = true;
    }
    	System.out.print (names[0]);
    
    // Sort Names
    String[] newNames= new String[amount];
    for (int l = 0; l < amount; l++){
    	newNames[l] = names[l];
    }
    for (int x = 0; x < amount; x++){
    	Arrays.sort(newNames);
    }
    complete1 = true;
    }
    
    if (answer == 2 && complete1 == false){
    	System.out.println("Cannot complete option 2. Please complete option 1 first.");
    }
    
    
    if (answer == 2 && complete1 == true){
    // Get Student #
    
    String[] numbs = new String[amount];
    for (int k = 0; k < amount; k ++){
    	System.out.print("What is the unique 8 digit student number for '" + names[k]+"'.");
    	Scanner takeNumb = new Scanner(System.in);
    	numbs[k] = takeNumb.nextLine();
    	
    }
    while (checkLength == true){
    	for (int i = 0; i<amount; i++){
    		if (numbs[i].length() != 8) {
    			System.out.println("Student number is incorrect length. Re-input student number for '" + names[i] + "'.");
    			Scanner fixNumb = new Scanner(System.in);
    			numbs[i] = fixNumb.nextLine();
    		}
    		else if (numbs[i].length() == 8){
    			checkLength = false;
    		}
    	}
    }
    if (amount > 1){
    while (checking == true){
    for (int n = 0; n < amount - 1; n++) {
    	if (numbs[n].equals(numbs[n+1])) {
    		match1 = true;
    		spot = n;	
    	}
    }
    	if (numbs [0].equals(numbs[amount-1])) {
    		match2 = true;
    	}
    if (match1 == false && match2 == false){
    	break;
    }
    if (match1 == true){
    	System.out.println("Error in student number input for '" + names[spot]+ "' and '" + names[spot+1]+ "'.");
    	System.out.println("Re-enter the unique 8 digit student number for '" + names[spot] +"'.");
    	Scanner newNumb = new Scanner(System.in);
    	numbs[spot] = newNumb.nextLine();
    	System.out.println("Re-enter the unique 8 digit student number for '" + names[spot+1] + "'.");
    	Scanner otherNumb = new Scanner(System.in);
    	numbs[spot+1] = otherNumb.nextLine();
    	match1 = false;
    }
    if (match2 == true){
    	System.out.println("Error in student number input for '"+ names[0]+"' and '" + names[amount-1] + "'."  );
    	System.out.println("Re-enter the unique 8 digit student number for '" + names[0] +"'.");
    	Scanner newCode = new Scanner(System.in);
    	numbs[0] = newCode.nextLine();
    	System.out.println("Re-enter the unique 8 digit student number for '" + names [amount - 1] + "'.");
    	Scanner otherCode = new Scanner(System.in);
    	numbs[amount-1] = otherCode.nextLine();
    	match2=false;
    }
    }
    }
    complete2 = true;
    }
    if (answer == 3 && complete1 == false){
    	System.out.println("Cannot complete option 3. Please complete option 1 first.");
    }
    if (answer == 3 && complete1 == true){
    	
    //Obtain marks from the different assignments
    int nums = 0;
    System.out.println("How many marks are you inputting for each student?");
    Scanner getNumb = new Scanner(System.in);
    nums = getNumb.nextInt(); 	
    if (nums > 5){
    	System.out.println("Error! Amount of marks exceeds the limit of 5.");
    	System.out.println("Re-input number of marks.");
    	Scanner getNewNumb = new Scanner(System.in);
    	nums = getNewNumb.nextInt();
    }
    int[] marks1 = new int[nums];
    int[] marks2 = new int[nums];
    int[] marks3 = new int[nums];
    int[] marks4 = new int[nums];
    int[] marks5 = new int[nums];
    int[] total = new int[nums];
    
    for (int r = 0; r<nums; r++){
    	System.out.println("What is the total for assignment " + (r+1) +".");
    	Scanner getTotal = new Scanner(System.in);
    	total[r] = getTotal.nextInt();
    }
    
    	if (nums == 1) {
    		for (int t = 0; t <amount; t++){
    			System.out.println("What mark did '" + newNames[t] + "' receive for assignment?");
    			Scanner getMark = new Scanner(System.in);
    			marks1[t] = getMark.nextInt();
    			
    			while (checkMark1 == true){
    				if (marks1[t] > total[0]){
    					System.out.println("Error in mark input. Please re-input mark for assignment 1 for '" + newNames[t] +"'.");
    					System.out.println("The assignment is out of " + total[0] +".");
    					Scanner newMark = new Scanner(System.in);
    					marks1[t] = newMark.nextInt();
    				}
    				else if (marks1[t] <= total[0]){
    					checkMark1 = false;
    				}
    			}
    			if (t == amount-1 && checkMark1 == false){
    				break;
    			}
    			checkMark1 = true;
    			}
   			}
    	if(nums ==2){
    		for (int t = 0; t < amount; t++){
    				System.out.println("What mark did '" + newNames[t] + "' receive for assignment 1?");
    				Scanner getMark = new Scanner(System.in);
    				marks1[t] = getMark.nextInt();
    				
    				while (checkMark1 == true){
    				if (marks1[t] > total[0]){
    					System.out.println("Error in mark input. Please re-input mark for assignment 1 for '" + newNames[t] +"'.");
    					System.out.println("The assignment is out of " + total[0] +".");
    					Scanner newMark = new Scanner(System.in);
    					marks1[t] = newMark.nextInt();
    				}
    				else if (marks1[t] <= total[0]){
    					checkMark1 = false;
    				}
    			}
    			if (t == amount -1 && checkMark1 == false){
    					break;
    				}
    			checkMark1 = true;
    		}
    		for (int q = 0; q < amount; q++){
    				System.out.println("What mark did '" +newNames [q] + "' receive for assignment 2?");
    				Scanner theMark = new Scanner (System.in);
    				marks2[q] = theMark.nextInt();
    			
    				while (checkMark2 == true){
    				if (marks2[q] > total[1]){
    					System.out.println("Error in mark input. Please re-input mark for assignment 2 for '" + newNames[q] +"'.");
    					System.out.println("The assignment is out of " + total[1] +".");
    					Scanner newMark = new Scanner(System.in);
    					marks1[q] = newMark.nextInt();
    				}
    				else if (marks1[q] <= total[1]){
    					checkMark2 = false;
    				}
    			}
    				if (q == amount-1 && checkMark2 == false){
    					break;
    				}
    			checkMark2 = true;
    			}
    			
    		}
    		
    	if(nums == 3){
    		for (int t = 0; t <amount; t++){
    			System.out.println("What mark did '" + newNames[t] + "' receive for assignment 1?");
    			Scanner getMark = new Scanner(System.in);
    			marks1[t] = getMark.nextInt();
    			
    			while (checkMark1 == true){
    				if (marks1[t] > total[0]){
    					System.out.println("Error in mark input. Please re-input mark for assignment 1 for '" + newNames[t] +"'.");
    					System.out.println("The assignment is out of " + total[0] +".");
    					Scanner newMark = new Scanner(System.in);
    					marks1[t] = newMark.nextInt();
    				}
    				else if (marks1[t] <= total[0]){
    					checkMark1 = false;
    				}
    			}
    			if (t == amount-1 && checkMark1 == false){
    				break;
    			}
    			checkMark1 = true;
    		}
    
    		for (int q = 0; q < amount; q++){
    			System.out.println("What mark did '"+ newNames [q] + "' receive for assignment 2?");
    			Scanner theMark = new Scanner (System.in);
    			marks2[q] = theMark.nextInt();
    		
    			while (checkMark2 == true){
    				if (marks2[q] > total[1]){
    					System.out.println("Error in mark input. Please re-input mark for assignment 2 for '" + newNames[q] +"'.");
    					System.out.println("The assignment is out of " + total[1] +".");
    					Scanner newMark = new Scanner(System.in);
    					marks2[q] = newMark.nextInt();
    				}
    				else if (marks2[q] <= total[1]){
    					checkMark2 = false;
    				}
    			}
    				if (q == amount-1 && checkMark2 == false){
    				break;
    			}
    			checkMark2 = true;
    			}
    		

    		for (int c = 0; c < amount; c++){
    			System.out.println("What mark did '" +newNames [c] + "' receive for assignment 3?");
    			Scanner otherMark = new Scanner (System.in);
    			marks3[c] = otherMark.nextInt();
    			
    			while (checkMark3 == true){
    				if (marks3[c] > total[1]){
    					System.out.println("Error in mark input. Please re-input mark for assignment 2 for '" + newNames[c] +"'.");
    					System.out.println("The assignment is out of " + total[2] +".");
    					Scanner newMark = new Scanner(System.in);
    					marks3[c] = newMark.nextInt();
    				}
    				else if (marks3[c] <= total[2]){
    					checkMark3 = false;
    				}
    			}
			if (c == amount-1 && checkMark3 == false){
    				break;
    		}
    	    				checkMark3 = true;
    		}
    	
    	}

    	if (nums == 4){
    		for (int t = 0; t <amount; t++){
    			System.out.println("What mark did '" + newNames[t] + "' receive for assignment 1?");
    			Scanner getMark = new Scanner(System.in);
    			marks1[t] = getMark.nextInt();
    			
    			while (checkMark1 == true){
    				if (marks1[t] > total[0]){
    					System.out.println("Error in mark input. Please re-input mark for assignment 1 for '" + newNames[t] +"'.");
    					System.out.println("The assignment is out of " + total[0] +".");
    					Scanner newMark = new Scanner(System.in);
    					marks1[t] = newMark.nextInt();
    				}
    				else if (marks1[t] <= total[0]){
    					checkMark1 = false;
    				}
    			}
    				if (t == amount-1 && checkMark1 == false){
    				break;
    			}
    			checkMark1 = true;
    			}
    		
    			
    			
    		for (int q = 0; q < amount; q++){
    			System.out.println("What mark did '" +newNames [q] + "' receive for assignment 2?");
    			Scanner theMark = new Scanner (System.in);
    			marks2[q] = theMark.nextInt();
    			while (checkMark2 == true){
    				if (marks2[q] > total[1]){
    					System.out.println("Error in mark input. Please re-input mark for assignment 2 for '" + newNames[q] +"'.");
    					System.out.println("The assignment is out of " + total[1] +".");
    					Scanner newMark = new Scanner(System.in);
    					marks1[q] = newMark.nextInt();
    				}
    				else if (marks2[q] <= total[1]){
    					checkMark2 = false;
    				}
    			}
    			if (q == amount -1 && checkMark2 == false){
    				break;
    			
    			}
    			checkMark2 = true;
    			}
    		

    		for (int c = 0; c < amount; c++){
    			System.out.println("What mark did '"+ newNames [c] + "' receive for assignment 3?");
    			Scanner otherMark = new Scanner (System.in);
    			marks3[c] = otherMark.nextInt();
    			while (checkMark3 == true){
    				if (marks3[c] > total[1]){
    					System.out.println("Error in mark input. Please re-input mark for assignment 2 for '" + newNames[c] +"'.");
    					System.out.println("The assignment is out of " + total[2] +".");
    					Scanner newMark = new Scanner(System.in);
    					marks3[c] = newMark.nextInt();
    				}
    				else if (marks3[c] <= total[2]){
    					checkMark3 = false;
    				}
    			}
    				if(c == amount-1 && checkMark3 == false){
    				break;
    					}
    				checkMark3 = true;
    		
    		
    			}
		
    		for (int v = 0; v < amount; v++){
    			System.out.println("What mark did '" +newNames [v] + "' receive for assignment 4?");
    			Scanner lesMark = new Scanner (System.in);
    			marks4[v] = lesMark.nextInt();
    			while (checkMark4 == true){
    				if (marks4[v] > total[1]){
    					System.out.println("Error in mark input. Please re-input mark for assignment 2 for '" + newNames[v] +"'.");
    					System.out.println("The assignment is out of " + total[3] +".");
    					Scanner newMark = new Scanner(System.in);
    					marks4[v] = newMark.nextInt();

    			}
    			checkMark2 = true;
    			}

    		for (int c = 0; c < amount; c++){
    			System.out.println("What mark did '"+ newNames [c] + "' receive for assignment 3?");
    			Scanner otherMark = new Scanner (System.in);
    			marks3[c] = otherMark.nextInt();
    			while (checkMark3 == true){
    				if (marks3[c] > total[1]){
    					System.out.println("Error in mark input. Please re-input mark for assignment 2 for '" + newNames[c] +"'.");
    					System.out.println("The assignment is out of " + total[2] +".");
    					Scanner newMark = new Scanner(System.in);
    					marks3[c] = newMark.nextInt();
    				}
    				else if (marks3[c] <= total[2]){
    					checkMark3 = false;
    				}
    			}
    			if (c == amount-1 && checkMark3 == false){
    				break;
    			}
    			checkMark3 = true;
    		}
    		
    		for (int v = 0; v < amount; v++){
    			System.out.println("What mark did '"+ newNames [v] + "' receive for assignment 4?");
    			Scanner lesMark = new Scanner (System.in);
    			marks4[v] = lesMark.nextInt();
    			while (checkMark4 == true){
    				if (marks4[v] > total[1]){
    					System.out.println("Error in mark input. Please re-input mark for assignment 2 for '" + newNames[v] +"'.");
    					System.out.println("The assignment is out of " + total[3] +".");
    					Scanner newMark = new Scanner(System.in);
    					marks4[v] = newMark.nextInt();
    				}
    				else if (marks4[v] <= total[3]){
    					checkMark4 = false;
    				}
    			}
    			if (v == amount-1 && checkMark4 == false){
    				break;
    			}
    			checkMark4 = true;
    			}

    		for (int p = 0; p <amount; p++){
    			System.out.println("What mark did '"+ newNames [p] + "' receive for assignment 4?");
    			Scanner tehMark = new Scanner (System.in);
    			marks5[p] = tehMark.nextInt();
    			while (checkMark5 == true){
    				if (marks5[p] > total[1]){
    					System.out.println("Error in mark input. Please re-input mark for assignment 2 for '" + newNames[p] +"'.");
    					System.out.println("The assignment is out of " + total[4] +".");
    					Scanner newMark = new Scanner(System.in);
    					marks5[p] = newMark.nextInt();
    				}
    				else if (marks5[p] <= total[4]){
    					checkMark5 = false;
    				}
    			}
    			if (p == amount-1 && checkMark5 == false){
    				break;
    			}
    			checkMark5 = true;
    		}
   		}
   		complete3 = true;
    }
    
    
    // Give Individual Reports
    if (answer == 4 && complete1 == false && complete2 == false && complete3 == false){
    System.out.println("Cannot complete option 4. Please complete option 1,  option 2, and option 3 first.");
    }
    if(answer == 4 && complete1 == true && complete2 == false && complete3 == false){
    	System.out.println("Cannot complete option 4. Please complete option 2 and 3 first.");
    }
    if (answer == 4 && complete1 == false && complete2 == true && complete3 == false){
    	System.out.println("Cannot complete option 4. Please complete option 1 and 3 first.");
    }
    if (answer == 4 && complete1 == false && complete2 == false && complete3 == true){
    	System.out.println("Cannot complete option 4. Please complete option 1 and 2 first.");
    }
    if (answer == 4 && complete1 == true && complete2 == true && complete3 == false){
    	System.out.println("Cannot complete option 4. Please complete option 3 first.");
    }
    if (answer == 4 && complete1 == false && complete2 == true && complete3 == true){
    	System.out.println("Cannot complete option 4. Please complete option 1 first.");
    }
    if (answer == 4 && complete1 == true && complete2 == false && complete3 == true){
    	System.out.println("Cannot complete option 4. Please complete option 2 first.");
    }
    if (answer == 4 && complete1 == true && complete2 == true && complete3 == true){
    int student = 0;
    System.out.println("Which student would you like a report for?");
    for (int o = 0; o < amount; o++){
    		System.out.println((o+1) + "- '" +newNames[o]+"'.");
    	}
    Scanner printOut = new Scanner(System.in);
    student = printOut.nextInt();
    System.out.println("STUDENT REPORT FOR '" + newNames[student-1] +"'.");
    System.out.println("STUDENT CODE: " + numbs[student-1] +".");
    if (nums == 1){
    	System.out.println("ASSIGNMENT 1: " + marks1[student-1] +"/" + total[0]);
    }
    if (nums == 2){
    	System.out.println("ASSIGNMENT 1: " + marks1[student-1] +"/" + total[0]);
    	System.out.println("ASSIGNMENT 2: " + marks2[student-1] +"/" + total[1]);
    }
    if (nums ==3){
    	System.out.println("ASSIGNMENT 1: " + marks1[student-1] +"/" + total[0]);
    	System.out.println("ASSIGNMENT 2: " + marks2[student-1] +"/" + total[1]);
    	System.out.println("ASSIGNMENT 3: " + marks3[student-1] +"/" + total[2]);
    }
    if (nums == 4){
    	System.out.println("ASSIGNMENT 1: " + marks1[student-1] +"/" + total[0]);
    	System.out.println("ASSIGNMENT 2: " + marks2[student-1] +"/" + total[1]);
    	System.out.println("ASSIGNMENT 3: " + marks3[student-1] +"/" + total[2]);
    	System.out.println("ASSIGNMENT 4: " + marks4[student-1] +"/" + total[3]);
    }
     if (nums == 5){
    	System.out.println("ASSIGNMENT 1: " + marks1[student-1] +"/" + total[0]);
    	System.out.println("ASSIGNMENT 2: " + marks2[student-1] +"/" + total[1]);
    	System.out.println("ASSIGNMENT 3: " + marks3[student-1] +"/" + total[2]);
    	System.out.println("ASSIGNMENT 4: " + marks4[student-1] +"/" + total[3]);
    	System.out.println("ASSIGNMENT 5: " + marks5[student-1] +"/" + total[4]);
    }
    }
    
    // Print Class Report
    if (answer == 5 && complete1 == false && complete3 == false){
    	System.out.println("Cannot complete option 5. Please complete option 1 and option 3 first.");
    }
    if (answer == 5 && complete1 == false && complete3 == true){
    	System.out.println("Cannot complete option 5. Please complete option 1  first.");
    }
    if (answer == 5 && complete1 == true && complete3 == false){
    	System.out.println("Cannot complete option 5. Please complete option 3 first.");
    }
    if (answer == 5 && complete1 == true && complete3 == true){
    	
    double[] average = new double[amount];
    double[] sum = new double[amount];
    
    if (nums == 1){
    		for (int i = 0; i < amount; i++){
    			sum[i] = marks1[i];
    		}
    	}
    	if (nums == 2){
    		for (int i = 0; i < amount; i++){
    			sum[i] = marks1[i] + marks2[i];
    		}
    	}
    	if (nums == 3){
    		for (int i = 0; i < amount; i++){
    			sum[i] = marks1[i] + marks2[i] + marks3[i];
    		}
    	}
    	if (nums == 4){
    		for (int i = 0; i < amount; i++){
    			sum[i] = marks1[i] + marks2[i] + marks3[i] + marks4[i];
    		}
    	}
    	if (nums == 5){
    		for (int i = 0; i < amount; i++){
    			sum[i] = marks1[i] + marks2[i] + marks3[i] + marks4[i] + marks5[i];
    		}
    	}
    	
    	
    for (int u = 0; u < amount; u++){
    	if (nums == 1){
    		average[u] = (sum[u] / total[0]) * 100; 	
    	}
    	if (nums == 2){
    		average[u] = (sum[u] / (total[0] + total[1])) * 100;
    	}
    	if (nums == 3){
    		average[u] = (sum[u] / (total[0] + total[1] + total[2])) * 100;
    	}
    	if (nums == 4){
    		average[u] = (sum[u] / (total[0] + total[1] + total[2] + total[3])) * 100;
    	}
    	if (nums == 5){
    		average[u] = (sum[u] / (total[0] + total[1] + total[2] + total[3] + total[4])) * 100;
    	}
    }	
    System.out.println("CLASS REPORT");
    for (int g = 0; g <amount; g++){
    	System.out.println("STUDENT: "+ newNames[g]);
    	System.out.println("OVERALL MARK: " + average[g]+ "%") ;
    }
    complete5 = true;
    }
    
    
    // Add/Remove Students
    if (answer == 6 && complete1 == false){
    	System.out.println("Cannot complete option 6. Please complete option 1 first.");
    }
    if (answer == 6 && complete1 == true){
    
    int response;
    int position = 0;
    System.out.println("Do you wish to add or remove students?");
    System.out.println("Input 1 for add. Input 2 for remove.");
    Scanner option = new Scanner(System.in);
    response = option.nextInt();
    String[] otherNames = new String[amount+1];
    if (response == 1){
    	for (int y = 0; y < amount; y++){
    		otherNames[y] = names[y];
    	}
    	System.out.println("Enter the new name in the following format: Last Name, First Name.");
    	Scanner addName = new Scanner(System.in);
    	otherNames[amount] = addName.nextLine();
    	Arrays.sort(newNames);
    }
    if (response == 2){
    	System.out.println("Which student do you wish to remove?");
    	System.out.println("Input the corresponding number.");
    	for (int z = 0; z < amount; z++){
    		System.out.println((z+1) + "- '" +newNames[z]+"'.");
    	}
    	Scanner removeName = new Scanner(System.in);
    	position = removeName.nextInt();
    	for (int b =0; b < amount; b++){
    		if (b == (position-1)){
    		newNames [b] = "";
    		}
    	}  	
    }
    Arrays.sort(newNames);
    for (int a = 0; a < amount; a++){
    	System.out.println("NEW CLASS LIST");
    	System.out.println(newNames[a]);

    }
    complete6 = true;
    }
    
    
    
    
    if (complete1 == true && complete2 == true && complete3 == true && complete4 == true && complete5 ==true && complete6 == true){
    	System.out.println("You have completed all options.");
    	break;
    }
    
    }
    System.out.println("Thank you for using Marks Manager");
    System.out.println("By: Jonathan Sepulveda");
    
    }
    
}
    	// TODO, add your application code