Why is my dialog box not popping up and why is it not working, please help me fix it. and possibly give me an example My Java code is below import javax.swing.JOptionPane; public class HELPME { public static void main(String[] args) { String inputString; //For reading input int numA; int numB; int numC; int numD; double gpa;
Why is my dialog box not popping up and why is it not working, please help me fix it. and possibly give me an example My Java code is below
import javax.swing.JOptionPane;
public class HELPME
{
public static void main(String[] args)
{
String inputString; //For reading input
int numA;
int numB;
int numC;
int numD;
double gpa;
// Have user input the number of letter grades they earned.
inputString = JOptionPane.showInputDialog(null, "Enter the number of A grades received: ");
numA =Integer.parseInt(inputString);
inputString = JOptionPane.showInputDialog(null, "Enter the number of B grades received: ");
numB =Integer.parseInt(inputString);
inputString = JOptionPane.showInputDialog(null, "Enter the number of C grades received: ");
numC =Integer.parseInt(inputString);
inputString = JOptionPane.showInputDialog(null, "Enter the number of D grades received: ");
numD =Integer.parseInt(inputString);
// Constants representing point values and credits
final int A_output = 6;
final int B_output = 4;
final int C_output = 3;
final int D_output = 1;
final int Points = 6;
// Calculate the total number of courses attempted
int numberOfCourses = numA + numB + numC + numD;
int totalCreditsAttempted = numberOfCourses * Points;
// Calculate the weighted total points earned
int totalPointsEarned = (numA * A_output * Points) +
(numB * B_output * Points) +
(numC * C_output * Points) +
(numD * D_output * Points);
double gpa = (double) totalPointsEarned / totalCreditsAttempted;// Calculate the GPA
JOptionPane.showMessageDialog("The GPA for attempting 24 credit hours and earned grades is: %.3f", gpa); // Display the GPA with 3 decimal places
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 6 images