We let students take courses Pass-Fail or for a letter grade.
Get the user’s score (a double) and tell them what grade they are getting.
You’ll also have to ask if they are taking the course Pass-Fail or for a letter grade.
Do this by taking a yes or no answer to the question: “Are you taking the course Pass-Fail?”
A passing grade for Pass-Fail is 55 or above – they should get a “PASS” for that or a “FAIL” otherwise.
The letter grades follow the standard college 60, 70, 80, 90 pattern for F,D,C,B,A (no plus/minus).
import javax.swing.JOptionPane;
public class passFail {
public static void main(String[] args) {
final String YES = "yes";
final String NO = "no";
final double PASS_FAIL = 55;
final double A_MIN = 90;
final double B_MIN = 80;
final double C_MIN = 70;
final double D_MIN = 60;
String userName;
double studentGrade;
String userChoice;
String inputString;
userName = JOptionPane.showInputDialog("Hello there, whats your name?");
inputString = JOptionPane.showInputDialog(userName + " what is your grade?");
studentGrade = Integer.parseInt(inputString);
userChoice = JOptionPane.showInputDialog(userName + " Are you taking the course Pass-Fail? (yes/no)");
///ASSUMING VALID GRADE 0 - 100
if (userChoice.equals(YES)){
if(studentGrade >= PASS_FAIL)
System.out.println(userName + ", you have passed!!");
else
System.out.println(userName + ", you have failed :(");
}
else {
if(studentGrade >= A_MIN )
System.out.println(userName + ", you have a A!!!");
else if(studentGrade >= B_MIN )
System.out.println(userName + ", you have a B!!");
else if(studentGrade >= C_MIN )
System.out.println(userName + ", you have a C!");
else if(studentGrade >= D_MIN )
System.out.println(userName + ", you have a D");
else
System.out.println(userName + ", you have a F :(");
}
}
}