I'm new to Java and trying to write a program that asks your name, income, fed and state tax rate and then calculates how much you are supposed to pay in taxes. Its supposed to include dialog boxes. My problem is this: I have done all the code and put in the parseDouble() method but when I go to calculate, Eclipse is giving me the error (stateTaxRate cannot be resolved to a variable and its doing the same thing with fedTaxRate variable too!) I'm super stuck.
import javax.swing.JOptionPane;
public class FedAndStateTaxes {
public static void main(String[] args) {
String yourName= JOptionPane.showInputDialog("What is your name?");
JOptionPane.showMessageDialog(null, "Name: " + yourName);
String yearlyIncome = JOptionPane.showInputDialog("What is your yearly income?");
try {double num = Double.parseDouble(yearlyIncome);
JOptionPane.showMessageDialog(null, "Yearly Income: "+ num);
}
catch(NumberFormatException e){
JOptionPane.showMessageDialog(null,"Error. Number input only please.");
}
String fTaxRate = JOptionPane.showInputDialog("Please enter your federal tax rate");
try { double fedTaxRate = Double.parseDouble(fTaxRate);
JOptionPane.showMessageDialog(null, "Federal Tax Rate: " + fedTaxRate +"%");
}
catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "Error. Number input only please.");
}
String sTaxRate = JOptionPane.showInputDialog("Pleae enter your state tax rate");
try {
double stateTaxRate = Double.parseDouble(sTaxRate);
JOptionPane.showMessageDialog(null, "State Tax Rate: " + stateTaxRate + "%");
}
catch(NumberFormatException e) {
JOptionPane.showMessageDialog(null,"Error. Number input only please");
}
double calculateIncome = (stateTaxRate);
I tried changing the parameter/variable names in the parseDouble()method. I expected it to call back to the string variable that I converted into a double, but instead it just couldn't resolve.