Hello, I'm trying to write a simple java program that will convert letter grade to number. It should ask user to input letter and then a popup window will come up and tell them the number value for that particular letter. If user adds + or - it should decrease value by .3. I think I need to use if then statements but this is what I have so far...
import java.util.Scanner; import javax.swing.*; /** * Auto Generated Java Class. */ public class TranslateGrade { public static final int A = 4; public static void main(String[] args) { String input = JOptionPane.showInputDialog("Enter a letter grade:"); String grade=input; JOptionPane.showMessageDialog(null, grade); System.exit(0); } }
That will not work because the output will display a string and not numeric value so I'm kinda stuck right now and trying to figure out how to apply if or else statements to this.
i find it annoying when they teach you how to use GUI before knowing the basics. You need a converter to say what each "letter" = in a number form.
I got this to work but I just found out that I need to create a class named Grade with a method getNumericGrade. . TranslateGrade program should test the Grade class. import java.util.Scanner; import javax.swing.*; public class TranslateGrade2{ public static void main(String[] args) { int numberGrade; char letterGrade; String x = JOptionPane.showInputDialog("Enter a letter grade:"); letterGrade = x.charAt(0); if(letterGrade == 'A' ) { JOptionPane.showMessageDialog(null, "4"); } else if (letterGrade == 'B') { JOptionPane.showMessageDialog(null, "3"); } else if (letterGrade == 'C') { JOptionPane.showMessageDialog(null, "2"); } else if (letterGrade == 'D') { JOptionPane.showMessageDialog(null, "1"); } } }
Got it!
Join our real-time social learning platform and learn together with your friends!