Java classes
I am new to Java and I am trying to create a Validator Class to validate my application. Here is the gui part:
//Thomas Tate
//Project 2 -GUI
import javax.swing.*;
public class GUIGradeApp
{
public static void main(String[] args)
{
//defines variables
double userEntry = 0;
String dataEntry = "tyt";
double gradeTotal = 0;
double highest = 0;
double lowest = 99999.0;
double gradeAverage = 0;
int gradeCount = 0;
String letterGrade = "";
//gets inout from the user
String strFirstMessage = ("Please enter a test score");
dataEntry = JOptionPane.showInputDialog(strFirstMessage, JOptionPane.ERROR_MESSAGE);
//loop that calculates totals.
while (!dataEntry.equalsIgnoreCase("x"))
{
gradeTotal = gradeTotal + userEntry;
gradeCount = gradeCount + 1;
highest = Math.max(highest, userEntry);
lowest = Math.min(lowest, userEntry);
String strSecondMessage = ("Please enter a test score,\n or 'x' to view data results.");
dataEntry = JOptionPane.showInputDialog(strSecondMessage, JOptionPane.ERROR_MESSAGE);
}
//creates letter grade
gradeAverage = gradeTotal / gradeCount;
if (gradeAverage <= 89.5 || gradeAverage >= 100.00)
letterGrade = "A";
else if (gradeAverage <= 79.5 || gradeAverage > 89.5)
letterGrade = "B";
else if (gradeAverage <= 69.5 || gradeAverage > 79.5)
letterGrade = "C";
else if (gradeAverage <= 59.5 || gradeAverage > 69.5)
letterGrade = "D";
else
letterGrade = "F";
String strSecondMessage = "Number of scores: " + gradeCount + "\n"
+ "Average score: " + gradeAverage + "\n"
+ "Letter Grade: " + letterGrade +"\n"
+ "Best score: " + highest + "\n"
+ "Press enter to continue entering scores,\nor 'x' to exit.";
JOptionPane.showInputDialog(strSecondMessage, JOptionPane.ERROR_MESSAGE);
}
}
And here is the validator class:
public class Valdiator
{
//Validator val = new Validator();
//}
public static getIsValid(string dataEntry)
{
while (!dataEntry.equalsIgnoreCase("x"))
{
try
{
userEntry = Double.parseDouble(dataEntry);
if (userEntry > 100.00 || userEntry < 0.0)
{
throw new Exception();
}
}
catch (Exception e)
{
String thirdMessage = ("Invalid entry. Please enter valid data");
dataEntry = JOptionPane.showInputDialog(strthirdMessage, JOptionPane.ERROR_MESSAGE);
}
return userEntry;
}
}
}
How would i fix this? I would like to call the validiator class in my GUI application but I still don't know how? Can anyone help?

