Hi super cool experts!
Big Java noobie here and first time poster, so sorry in advance if this forum isn't for people like me. I'm trying to write a silly math program as my first user input test, but I seem to be getting error with the variables from the buffered reader.
Here is my code. :)
import java.io.*;
public class MathNerd {
public static void main (String args []) {
String firstNumber;
String secondNumber;
String thirdNumber;
String fourthNumber;
String fithNumber;
String yesandNo;
BufferedReader readfirstNumber;
BufferedReader readsecondNumber;
BufferedReader readthirdNumber;
BufferedReader readfourthNumber;
BufferedReader readfithNumber;
BufferedReader readyesandNo;
readfirstNumber = new BufferedReader (new InputStreamReader (System.in));
readsecondNumber = new BufferedReader (new InputStreamReader (System.in));
readthirdNumber = new BufferedReader (new InputStreamReader (System.in));
readfourthNumber = new BufferedReader (new InputStreamReader (System.in));
readfithNumber = new BufferedReader (new InputStreamReader (System.in));
readyesandNo = new BufferedReader (new InputStreamReader (System.in));
//Into into the program
System.out.println ("I'm a super geek math wiz that knows how to do math stuff");
System.out.println ("\nDo you believe me?");
try {
yesandNo = readyesandNo.readLine ();
System.out.println ("oh, you think " + yesandNo + " hu?");
System.out.println ("Lets test my skill since your such a smarty pants");
}
//try catch
catch (IOException ioe) {
System.out.println ("This is a yes or no question....wowsers");
}
//Program requests first number
System.out.println ("\nGive me any positive whole number math nooblet");
try {
firstNumber = readfirstNumber.readLine ();
System.out.println ("Pfft, is that the best number you could come up with, super lame");
System.out.println ("Processing....");
}
//try catch
catch (IOException ioe) {
System.out.println ("I said give me a number you non geeky pool of mud slug");
}
//Program requests second number
System.out.println ("Ok, give me another number and i'll multiply it by the last number");
System.out.println ("\nOh, and try to give me a better number this time...");
try {
secondNumber = readsecondNumber.readLine ();
System.out.println ("Hummm " + secondNumber + " isn't to bad for a math noob");
System.out.println ("Processing....");
}
//try catch
catch (IOException ioe) {
System.out.println ("I said give me a number you non geeky pool of mud slug");
}
//Program requests third number
System.out.println ("\nGive me another number and i'll divide it by the outcome of the first two");
try {
thirdNumber = readthirdNumber.readLine ();
System.out.println ("Are you kidding me? " + thirdNumber + " is the best you could come up with?");
System.out.println ("Sigh... oh well, we can all be math gurus like me I guess");
System.out.println ("Processing....");
}
//try catch
catch (IOException ioe) {
System.out.println ("I said give me a number you non geeky pool of mud slug");
}
//Program requests fourth number
System.out.println ("Now we're getting into the tricky parts");
System.out.println ("Give me a number this time to multiply agaisnt the outcome of the first three");
try {
fourthNumber = readfourthNumber.readLine ();
System.out.println ("YAWWWWNNNNNN");
System.out.println ("Processing....");
}
//try catch
catch (IOException ioe) {
System.out.println ("I said give me a number you non geeky pool of mud slug");
}
//Program requests fith number
System.out.println ("Give me one last number and I will divide it by the outcome of the last four");
try {
fithNumber = readfithNumber.readLine ();
System.out.println ("Processing....");
}
//try catch
catch (IOException ioe) {
System.out.println ("I said give me a number you non geeky pool of mud slug");
}
double oneNumber = Double.parseDouble(firstNumber);
double twoNumber = Double.parseDouble(secondNumber);
double threeNumber = Double.parseDouble(thirdNumber);
double fourNumber = Double.parseDouble(fourthNumber);
double fiveNumber = Double.parseDouble(fithNumber);
double calcOne = oneNumber * twoNumber;
double calcTwo = calcOne / threeNumber;
double calcThree = calcTwo * fourNumber;
double calcFour = fiveNumber / calcThree;
//Final answer and message
System.out.println ("Awwww yeah, the number is " + calcFour);
System.out.println ("Yes, the rumors are true, I am in fact...Da man!");
System.out.println ("Nerd word!");
}
}
*** Here is the error I keep getting.***
MathNerd.java:98: error: variable firstNumber might not have been initialized
double oneNumber = Double.parseDouble(firstNumber);
^
MathNerd.java:99: error: variable secondNumber might not have been initialized
double twoNumber = Double.parseDouble(secondNumber);
^
MathNerd.java:100: error: variable thirdNumber might not have been initialized
double threeNumber = Double.parseDouble(thirdNumber);
^
MathNerd.java:101: error: variable fourthNumber might not have been initialized
double fourNumber = Double.parseDouble(fourthNumber);
^
MathNerd.java:102: error: variable fithNumber might not have been initialized
double fiveNumber = Double.parseDouble(fithNumber);
^
5 errors