Grade
/* This program uses the JOptionPane It asks the user for 3 grades Then it will calculate the average of the grade And it will print out a letter grade according to the average * */ import javax.swing.JOptionPane;//needed for the swing class public class Grade { public static void main(String[] args) { String input; int score1, score2, score3; double average; //Gets the score for the first grade input = JOptionPane.showInputDialog("What is your first test score: "); score1 = Integer.parseInt(input); //Gets the score for the second grade input = JOptionPane.showInputDialog("What is your second test score: "); score2 = Integer.parseInt(input); //Gets the score for the third grade input = JOptionPane.showInputDialog("What is your third test score: "); score3 = Integer.parseInt(input); //Calculates the average of the grade average = (score1 + score2 + score3) / 3.0; //Using the if else-if statement to determine the user's letter grade if ( average < 60 ) { //Using JOptionpane to prints out the grade JOptionPane.showMessageDialog(null, "Your average is " + average + "Your grade is a F"); } else if ( average < 70 ) { JOptionPane.showMessageDialog(null,"Your average is " + average + " Your grade is a D"); } else if ( average < 80 ) { JOptionPane.showMessageDialog(null,"your average is " + average + " Your grade is a C"); } else if ( average < 90 ) { JOptionPane.showMessageDialog(null, "your average is " + average + " Your grade is a B"); } else if ( average <=100 ) { JOptionPane.showMessageDialog(null, "your average is " + average + " Your grade is an A"); } else { JOptionPane.showMessageDialog(null, "Invalid"); } System.exit(0); } }
< Java > <Home><Java Programs>