Anda di halaman 1dari 4

import java.io.*; import java.io.ObjectInputStream.GetField; public class GradesProgram { static BufferedReader Keyboard = new BufferedReader(new InputStreamReader( System.

in)); static int quiz1, quiz2,quiz3; static double tMidTerm; static double tFinal; static double tQuiz; static int[][] stdA=new int[3][5]; static int midTermExam = 0; static int finalExam = 0; static double finalScore = 0; static char grade; String name; public static void main(String[] args) throws IOException { if (args.length == 0) { printUsage(""); } else if(args.length!=15){ printUsage("The arguments are not as expected"); } else{ validateArgs(args); stdA[0][0]=convertStringToInt(args[0]); stdA[0][1]=convertStringToInt(args[1]); stdA[0][2]=convertStringToInt(args[2]); stdA[0][3]=convertStringToInt(args[3]); stdA[0][4]=convertStringToInt(args[4]); stdA[1][0]=convertStringToInt(args[5]); stdA[1][1]=convertStringToInt(args[6]); stdA[1][2]=convertStringToInt(args[7]); stdA[1][3]=convertStringToInt(args[8]); stdA[1][4]=convertStringToInt(args[9]); stdA[2][0]=convertStringToInt(args[10]);

stdA[2][1]=convertStringToInt(args[11]); stdA[2][2]=convertStringToInt(args[12]); stdA[2][3]=convertStringToInt(args[13]); stdA[2][4]=convertStringToInt(args[14]); for(int e=0;e<3;e++){ quiz1=stdA[e][0]; quiz2=stdA[e][1]; quiz3=stdA[e][2]; midTermExam = stdA[e][3]; finalExam = stdA[e][4]; getScore(); getLetterGrade(); System.out.println("SCORES FOR STUDENT " + ":" ); System.out.println("*****************************************"); System.out.println("FIRST QUIZ SCORE :" + quiz1); System.out.println("SECOND QUIZ SCORE :" + quiz2); System.out.println("THIRD QUIZ SCORE :" + quiz3); System.out.println("MID TERM EXAM SCORE :" + midTermExam); System.out.println("FINAL SCORE :" + finalExam); System.out.println("THE FINAL SCORE(%) :" + finalScore); System.out.println("YOUR FINAL GRADE IS :" + grade); System.out.println(); } } } public static void validateArgs(String[] a){ String q; for(int i=0;i<a.length;i++){ q=a[i]; try{ int h=Integer.parseInt(q); } catch(Exception ex){ printUsage("Quiz Marks should be integers"); System.exit(0); }

e+

} } public static int convertStringToInt(String s){ Integer it=Integer.parseInt(s); return it.intValue(); }

public static void printUsage(String s){ System.out.println(s); System.out .println("Please enter the marks of quiz1,quiz2,quiz3,Midterm and Final in the same order for student 1 ,2 and 3 as commnd line arguments");

} void getName(String name) throws IOException { System.out.println("Please Enter Your Name"); System.out.println("Students Caclculaed Final Scores"); System.out.println("and Letter Grades"); name = System.in.toString(); // int name = System.in.read(); }

static void getGardes() throws IOException { System.out.println("Please Enter Your first Quiz1 Grade:"); int quiz1 = System.in.read(); System.out.println("Please Enter Your second Quiz2 Grade:"); int quiz2 = System.in.read(); System.out.println("Please Enter Your midterm Grade:"); int midTermExam = System.in.read(); System.out.println("Please Enter Your Final Exam Grade:"); int finalExam = System.in.read(); } static void getScore() {

tQuiz = (((quiz1 + quiz2 + quiz3)*25 )/ 30); tMidTerm = ((midTermExam * 35)/100); tFinal = ((finalExam *40)/100); finalScore = tQuiz + tMidTerm + tFinal; } static void getLetterGrade() { if (finalScore >= 90) { grade = 'A'; } else if (finalScore >= 80 && finalScore <90) { grade = 'B'; } else if (finalScore >= 70 && finalScore <80) { grade = 'C'; } else if (finalScore >= 60 && finalScore <70) { grade = 'D'; } else { grade = 'F'; } }