In: Computer Science
For input you can either a console Scanner or a dialog box (a modal dialog) and the static method showInputDialog() of the JOptionPane class which is within the javax.swing package like this String name= newJOptionPane.showInputDialog(” Please enter your data:”). Then convert the String object to a number using Integer.parseInt() or Double.parseDouble()
----
Write a java the ”Letter grade” program that inputs several test scores from user and displays for each the corresponding letter grade using a scale 90 – 80 – 70 – 50. Test thoroughly the program with different data sets of your own.
import javax.swing.JOptionPane;
public class LetterGrade {
public static void main(String[] args) {
while (true) {
//reading score from user
String str = JOptionPane.showInputDialog("Please enter your score (-1 to exit):");
//converting it into double
double score = Double.parseDouble(str);
//break if it is -1
if(score==-1) break;
//finding the letter for given score
String letter = getLetter(score);
//showing the score and letter
JOptionPane.showMessageDialog(null, score+" "+letter);
}
}
//returns letter grade for given score
private static String getLetter(double n) {
if (n >= 90)
return "A";
if (n >= 80)
return "B";
if (n >= 70)
return "C";
if (n >= 60)
return "D";
return "F";
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME