/*================================================================================== * FSP 2012 Assignment * Student ID : S10122534C * Student Name : Leonard Laura Rachel M * Module Group : FI05 * * ==================================================================================*/ import java.util.Scanner; public class S10122534c_Assignment { public static void main(String[] args) { final int MAXSIZE = 50; // maximum number of students String[] name = new String[MAXSIZE];// array to store the names of the students double[] caMark = new double[MAXSIZE];// array to store the Continuous Assessment marks double[] ctMark = new double[MAXSIZE];// array to store the Common Test marks double[] asgMark = new double[MAXSIZE];// array to store the Assignment marks double[] finalMark = new double [MAXSIZE]; // array to store the Final marks int count = 0; Scanner input = new Scanner(System.in); // initialize the array with students count = initialization(name,double[] caMark,double[] ctMark,double[] asgMark); int choice; finalMark = calculateFinalMark(count,caMark, ctMark, asgMark); do { choice = input.nextInt(); switch (choice) { case 1: displayStudentResults(name, caMark, ctMark, asgMark, finalMark, count);break; case 2: diplayFailedStudents(name, caMark, ctMark, asgMark, finalMark, count);break; case 3: addNewStudent(count);break; case 4: updateMark(asgMark, count);break; case 5: exit();break; default:System.out.print("Thank you."); } }while (choice != 0); } // method to initialize the arrays with students public static int initialization(String[] name, double[] caMark, double[] ctMark, double[] asgMark, double[] finalMark) { namer [0] = "Agnes Tan"; caMark [0] = 75; ctMark [0] = 68; asgMark [0] = 82; name [1] = "Benny Ong"; caMark [1] = 66; ctMark [1] = 30; asgMark [1] = 35; name [2] = "Denise Ng"; caMark[2] = 55; ctMark [2] = 42; asgMark [2] = 50; name [3] = "Jimmy Tay"; caMark [3] = 80; ctMark [3] = 76; asgMark[3] = 82; name [4] = "Evelyn Low"; caMark [4] = 70; ctMark [4] = 60; asgMark [4] = 65; return 5; } public static void displayMenu() { String[] nameArr; double[] caMarkArr; double[] ctMarkArr; double[] asgMarkArr; double[] finalMarkArr; { System.out.println ("MENU"); System.out.println ("========================================"); System.out.println (" [1]. Display the results of all students"); System.out.println (" [2]. Display the students who have failed"); System.out.println (" [3]. Add a new student"); System.out.println (" [4]. Update assignment mark of a student"); System.out.println (" [0]. Exit"); System.out.println ("Enter your option: _____ "); System.out.println ("========================================="); } } public static void displayStudentResults(String[] nameArr, double[] caMarkArr, double[] ctMarkArr, double[] asgMarkArr, double[] finalMarkArr) { int [] numArr = new int[50]; System.out.println("Student Name" + "CA" + "CT" + "ASG" + "FINAL" + "GRADE"); for (int i=0; i<numArr.length; i++) { System.out.println(nameArr[i] + caMarkArr[i] + ctMarkArr[i] + asgMarkArr[i] + finalMarkArr[i]); numArr[i]=i+1; } } //Calculate Final marks to compute whether the student has passed & to know the grades public static double calculateFinalMark(int count, double[] caMark, double[] ctMark, double[] asgMark) { int a = count; finalMark = (0.4 * caMark[a]) + (0.3 * ctMark[a]) + (0.3 * asgMark[a]); System.out.print(finalMark); count++; return finalMark; } public static void displayFailedStudents (String[] name, double[] caMark, double[] ctMark, double[] asgMark, double[] finalMark) { System.out.println("No" + "Student Name" + "CA" + "CT" + "ASG" + "FINAL" + "GRADE"); for (int l=0; l<count; l++) { if (finalMark < 50) System.out.print(name[l], caMark[l], ctMark[l], asgMark[l], finalMark[l]); } } public static void addNewStudent(int count) { System.out.println("Option 3: Add New Student"); System.out.println("Enter Student Name: "); String name = input.next(); System.out.println("Enter CA Marks: "); double caMarks = input.nextDouble(); System.out.println("Enter CT Marks: "); double ctMarks = input.nextDouble(); System.out.println("Enter ASG Marks: "); double asgMarks = input.nextDouble(); System.out.println("One Student Added."); count++; } public static void updateMark(int count, double asgMark) { int i = count; System.out.println("Option 4: Update Assignment Mark of a Student: "); System.out.println("Enter the serial number of the student to update : "); i = input.nextInt(); System.out.println("Enter new assignment mark : "); double asgMark = input.nextDouble(); System.out.println("The assignment mark is updated. "); asgMark[count-1] = asgMarks; } public static char gradeMark( double finalMark) { char gradeMark = 0; if (finalMark >=80) System.out.println("Grade A"); if ((finalMark >=70) && (finalMark < 80)) System.out.println("Grade B"); if ((finalMark >=60) && (finalMark < 70)) System.out.println("Grade C"); if ((finalMark >= 50) && (finalMark < 60)) System.out.println("Grade D"); if (finalMark < 50) System.out.println("Grade F"); return gradeMark; } }