Hi Netizens, I wish you guys can guide me in here. In the following code, I've compiled flawlessly and I didn't managed to get the output screen and I'm kind of in the dark since I didn't find the answer that I wanted through internet browsing after a while. Any reply will be appreciated :)
On the other side of the note, I managed to get the output with 3 variable in the showMessageDialog [output] but it disappear when I tried to add 'comment' variable inside.
//Enter the input for the marks and displays the corresponding grade using GUI
import javax.swing.JOptionPane;
import javax.swing.JFrame;
public class MarksGradeWithGUI
{
public static void main(String[] args)
{
int testScore;
int stu_id;
String name1;
String stu_matrix;
String input;
String stu_name;
String grade;
String comment;
//Get the student name.
name1 = JOptionPane.showInputDialog (null, "Please enter your name : ", "Your name", JOptionPane.QUESTION_MESSAGE);
//Obtain the student matrix number.
stu_matrix = JOptionPane.showInputDialog (null, "Please enter your 6-digit ID number: ", "Your Matrix Number", JOptionPane.QUESTION_MESSAGE);
//Get the numeric test score.
input = JOptionPane.showInputDialog (null, "Enter your numeric test score and I will tell you the grade: ", "Your score", JOptionPane.QUESTION_MESSAGE);
stu_name = (name1);
stu_id = Integer.parseInt (stu_matrix);
testScore = Integer.parseInt (input);
grade = null;
comment = "Try again for a better result!";
//Display the grade.
if (testScore < 40)
{
grade = "F";
comment = "Don't be sad! Try again!";
}
else
{
if (testScore < 50)
{
grade = "D";
comment = "Please put more effort!";
}
else
{
if (testScore < 65)
{
grade = "C";
comment = "Be more hardworking and you'll strive!";
}
else
{
if (testScore < 80)
{
grade = "B";
comment = "You're doing great! Just a little more for an A!";
}
else
{
if (testScore < 101)
{
grade = "A";
comment = "Congratulations!";
}
else
{
JOptionPane.showMessageDialog(null, "Invalid entry.\n" +
"Please enter your test score between (0-100)");
}
String output = "Name : " + stu_name + "\nMatrix ID : 0" + stu_id + "\nGrade : " + grade + "\nComment : " + comment;
JOptionPane.showMessageDialog (null, output, "Output Screen", JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
System.exit(0);
}
}