rendered paste body
/**
* Program Description: This program will calculate the average of a student over 3
* subjects and displays their grade
*
* By Amro Qandour
* Date: 31.08.2006
*/
import javax.swing.JOptionPane ;
import java.text.DecimalFormat;
import javax.swing.*;
public class StudentGrades
{
public static void main(String[]args)
{
final int limit=3;
double avrg=0;
double sum=0;
double result=0;
String doItAgain;
do
{
String lastName=JOptionPane.showInputDialog("Enter family name:");
String firstName=JOptionPane.showInputDialog("Enter first name:");
String firstUpper=firstName.toUpperCase();
char ch;
int index=0;
ch=firstUpper.charAt(0);
for (int count=1; count<=limit; count++)
{
String subject=JOptionPane.showInputDialog("Enter subject:");
do
{
String sResult=JOptionPane.showInputDialog("Enter result:");
result=Double.parseDouble(sResult);
}
while (result<0 || result>100);
grade(result);
JOptionPane.showMessageDialog(null,"Result for" + " " + ch + "."
+ " " + lastName + "\n" + subject + ":" + " " + grade(result));
sum=sum + result;
}
DecimalFormat fmt= new DecimalFormat(".##");
avrg=sum/3;
JOptionPane.showMessageDialog(null,"Average for" + " " + ch + "." + lastName
+ " " + "is:" + "\n" + fmt.format(avrg) );
doItAgain=JOptionPane.showInputDialog("Another student (y/n)?");
}
while (doItAgain.equalsIgnoreCase("y"));
}
public static String grade(double mark)
{
String message = "";
if (mark > 0 && mark < 50) {
message = "Fail";
}
if (mark >= 50 && mark < 60) {
message = "Pass";
}
if (mark >=60 && mark < 70) {
message = "Credit";
}
if (mark >=70 && mark < 80) {
message = "Distinction";
}
if (mark >=80 && mark <= 100) {
message = "High Distinction";
}
return(message);
}
}