Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Use string outside of loop Posted by Flightfanatic1 on 8 Mar 2010 at 1:02 PM
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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.