Thursday, March 6, 2008

TestGrades.java

import javax.swing.JOptionPane;

public class TestGrades
{
public static void main (String[] args)
{
String matricNo, grade;
int score;
int studentCount = 0;
int totalA=0;
int totalB=0;
int totalC=0;
int totalD=0;
int totalF=0;

while (studentCount<200)
{
matricNo = JOptionPane.showInputDialog(null, "Enter matric no:", "Test Grades", JOptionPane.QUESTION_MESSAGE);
String inputScore = JOptionPane.showInputDialog(null, "Enter score:", "Test Grades", JOptionPane.QUESTION_MESSAGE);
score = Integer.parseInt(inputScore);

if (score>=90 && score<=100) {
grade = "A";
totalA++;
}
else if (score>=78 && score<90) {
grade = "B";
totalB++;
}
else if (score>=65 && score<78) {
grade = "C";
totalC++;
}
else if (score>=50 && score<65) {
grade = "D";
totalD++;
}
else {
grade = "F";
totalF++;
}
System.out.println("Matric no: " + matricNo);
System.out.println("Score: " + score);
System.out.println("Grade: " + grade);
System.out.println();
studentCount++;
}
//JOptionPane.showMessageDialog(null, "Enter matric no:", "Test Grades", JOptionPane.INFORMATION_MESSAGE);
System.out.println("Total number of As is " + totalA);
System.out.println("Total number of Bs is " + totalB);
System.out.println("Total number of Cs is " + totalC);
System.out.println("Total number of Ds is " + totalD);
System.out.println("Total number of Fs is " + totalF);

System.exit(0);
}
}

No comments: