I've tried setting the if statement to either check for: " ", "", "\n", and 'null' to no avail.
The error I get:
Quote
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:992)
at java.lang.Double.parseDouble(Double.java:510)
at TestScores_1.averageScore(TestScores_1.java:73)
at TestScores_1_Input.main(TestScores_1_Input.java:16)
public class TestScores_1
{
// Declares the three test scores as strings, later to be parsed as double's.
private String testScore_1, testScore_2, testScore_3;
// This is a constructor method, that 'initializes' a new TestScores_1 object, with the specified values.
public TestScores_1()
{
testScore_1 = null;
testScore_2 = null;
testScore_3 = null;
}
// These are the mutator methods, where the user will set the
// values for testScore_1, testScore_2, and testScore_3.
public void set_1(String test1)
{
if (test1 == null) {
testScore_1 = "0";
} else {
testScore_1 = test1;
}
}
public void set_2(String test2)
{
if (test2 == null) {
testScore_2 = "0";
} else {
testScore_2 = test2;
}
}
public void set_3(String test3)
{
if (test3 == null) {
testScore_3 = "0";
} else {
testScore_3 = test3;
}
}
// These are the accessor methods, that will retrieve the values of the tests.
public String getTest_1()
{
return testScore_1;
}
public String getTest_2()
{
return testScore_2;
}
public String getTest_3()
{
return testScore_3;
}
// This method AVERAGES the test scores.
public double averageScore()
{
double t1, t2, t3, average_Score;
t1 = Double.parseDouble(testScore_1);
t2 = Double.parseDouble(testScore_2);
t3 = Double.parseDouble(testScore_3);
average_Score = (t1 + t2 + t3) / 3;
return average_Score;
}
}
import javax.swing.JOptionPane;
class TestScores_1_Input {
public static void main(String[] args) {
TestScores_1 testInput = new TestScores_1();
JOptionPane.showMessageDialog(null, "This program will take 3 user-inputted test scores and average them.");
testInput.set_1(JOptionPane.showInputDialog("What is your first test score?"));
testInput.set_2(JOptionPane.showInputDialog("What is your second test score?"));
testInput.set_3(JOptionPane.showInputDialog("What is your third test score?"));
JOptionPane.showMessageDialog(null, "Your three scores are: " + testInput.getTest_1() + ", " + testInput.getTest_2() + ", " + testInput.getTest_3());
if (testInput.averageScore() <= 25)
{
JOptionPane.showMessageDialog(null, "You're a dumb faggot. Your average is: Faggot");
}
else {
JOptionPane.showMessageDialog(null, "Your average is: " + testInput.averageScore());
}
System.exit(0);
}
}

New Topic/Question
Reply



MultiQuote





|