Hello, I am new to java. I am having an issue with a java program that I am making. It has a try-catch loop to make sure the user inputted a number, but I cant use the string outside of the loop.t from testa.java, and is supposed to send it to testb.java... I am getting the error:
testa.java:59: cannot resolve symbol
symbol : variable convAmountEuros
location: class testa
testb.convert(convAmountEuros, convExchangeRate);
The program uses 2 class files. It takes the input from testa.java, and sends 2 strings (amountEuros and exchangeRate) and sends those to testb.java to do all of the math there.. Any help is greatly appreciated!
The program is to convert euros - us dollars.
Code from testa.java
import javax.swing.*;
public class testa {
public static void main (String[] args){
String amountEuros = " ";
String exchangeRate;
double convExchangeRate = 0;
//double convAmountEuros;
int step = 1;
JFrame frame = new JFrame();
Icon menuIcon = new ImageIcon("logo.png");
//Display Welcome
JOptionPane.showMessageDialog(frame, "Welcome To Euro Convert\nPlease Click OK To Procede:", "Select an Option", JOptionPane.QUESTION_MESSAGE, menuIcon);
ImageIcon icona = new ImageIcon("1.jpg");
ImageIcon iconb = new ImageIcon("2.jpg");
while (step == 1){
//Input Total Number of Euros
amountEuros = JOptionPane.showInputDialog(null,"Please Input The Number Of Euros:");
try {
//Put Number of euros in constant
final double convAmountEuros = Double.parseDouble (amountEuros);
step++;
} catch (NumberFormatException nfe){
JOptionPane.showMessageDialog(frame, "INPUT ERROR: Please Input An Integer!");
}
}
while (step == 2){
//Input exchange rate
exchangeRate = JOptionPane.showInputDialog(null,"Please Input The Exchange Rate:");
try {
//convert to integer
convExchangeRate = Double.parseDouble (exchangeRate);
//testb.convert(convAmountEuros, convExchangeRate);
step++;
} catch (NumberFormatException nfe){
JOptionPane.showMessageDialog(frame, "INPUT ERROR: Please Input An Integer!");
}
}
//convert to integer
//convExchangeRate = Double.parseDouble (exchangeRate);
while (step == 3){
// testb.convert(convAmountEuros, convExchangeRate);
}
System.exit(1);
//end of main method
}
//end of class
}
Code from testb.java
import java.text.*;
import javax.swing.*;
public class testb {
public static double convert(double amountEuros, double exchangeRate)
{
//Set Decimal Formats
DecimalFormat tenths = new DecimalFormat ("#,###.##");
DecimalFormat round = new DecimalFormat ("#,###.##");
//Define Strings
double newamount = 0;
double roundedamount = 0;
newamount = (amountEuros*exchangeRate);
//System.out.println(newamount);
JFrame frame = new JFrame();
ImageIcon icon = new ImageIcon("flag.png");
//roundedamount = newamount;
//roundedamount = Math.round(roundedamount);
//Display message with all of the data
JOptionPane.showMessageDialog(frame, "The Amount of Euros Is: " + round.format(amountEuros) + "\nThe Exchange Rate Is: " + round.format(exchangeRate*.988) + "%\nExchangable US Dollars: " + round.format(newamount*.988) + "\nPayable US Dollars: "+round.format(newamount*.988), "Inane warning",JOptionPane.WARNING_MESSAGE,icon);
//throw back the strings
return(newamount);
//end of main method
}
//end of class
}
Thanks!
-Flightfanatic