Click to See Complete Forum and Search --> : Need Assistance with a goto or get statement


jbreedlove5
11-19-2003, 09:55 AM
I just started a class with Java about 3 weeks ago. I am at a point, I am having trouble or can't find any good documentation to goback or goto or return to something after a process is performed, so the user will have a chance to enter another selection rather than the program ending.

I am doing a currency conversion. After the user selects one of the choices from the menu, it takes that user to one of the cases, where other choices will be offered to the user and some processing is performed. Once that currency conversion process for that selection has completed, I need to take that user back to the menu selection, so they can choice another selection. I tried all kinds of things, but can't get anything to work. Attached is my code with what I attempted to loop back to the menu.
Just an fyi I took out case 3 so my thread would fit into this posting.

Thanks in advance!

import javax.swing.*;
public class thirdprogram { //Identifies the saved name of the program, secondprogram.java
private static final int EXIT_CHOICE = 9;

public static void main(String[] args){
int conversionChoice = getconversionChoice();
float dollar; // dollar is the float and the output of the conversion
String conversionInput;
while (conversionChoice != EXIT_CHOICE) {

conversionInput = JOptionPane.showInputDialog(null,"Type of conversion\n" +
"1. Euro\n" +
"2. Mexican Peso\n" +
"3. Canadian Dollar\n" +
"4. Japanese Yen\n" +
"5. Swiss Franc\n" +
"Enter the desired conversion: " +
"or '" + EXIT_CHOICE + "' to exit:\n"); //The User will get to choose which currency they want to convert
conversionChoice = Integer.parseInt(conversionInput);

switch (conversionChoice) {

case 1:
String euro;
float yourrate, percent;
euro = JOptionPane.showInputDialog(null,"Enter amount of European currency to be converted to U.S. Dollars");
yourrate = Float.parseFloat(euro); //Takes the user input of euro, and equates that to yourrate
dollar = yourrate/(float)1.1419; //Calculation that converts the currency into U.S. dollars
if (dollar > 100.00f){ /*If statement. If the conversion is greater than 100 U.S Dollars an additional 10% is granted.*/
percent = (float).10 * yourrate; //10% calculation
dollar = percent + dollar; //calculation for adding the 10% to the final dollar amount
}
if (dollar > 200.00f){ //If Statement. Greater than 200 dollars a message appears, "You are Rich"
JOptionPane.showMessageDialog(null,"You are Rich");

}else{
if (dollar < 200.00f){ //If statement. Less than $200.00 dollars a message appears, "You are a student"
JOptionPane.showMessageDialog(null,"You are a Student");
}
}
//Displays the final U.S dollar amount for the user, which includes the additional 10% if greater than $100.00 dollars
JOptionPane.showMessageDialog(null,"The U.S Dollar amount for Euro conversion is: " + dollar);


break;
// case (Converting the Mexican Peso currency to U.S. Dollars)
case 2:
String peso;
float yourrate1, percent1;
peso = JOptionPane.showInputDialog(null,"Enter amount of Mexican currency to be converted to U.S Dollars");
yourrate1 = Float.parseFloat(peso); //Takes the user input of peso's, and equates that to yourrate1
dollar = yourrate1/(float)0.0910; //Calculation that converts the currency into U.S. dollars
if (dollar > 100.00f){ /*If statement. If the conversion is greater than 100 U.S Dollars an additional 10% is granted.*/
percent1 = (float).10 * yourrate1; //10% calculation
dollar = percent1 + dollar; //calculation for adding the 10% to the final dollar amount
}
if (dollar > 200.00f){ //If Statement. Greater than 200 dollars a message appears, "You are Rich"
JOptionPane.showMessageDialog(null,"You are Rich");

}else{
if (dollar < 200.00f){ //If statement. Less than $200.00 dollars a message appears, "You are a student"
JOptionPane.showMessageDialog(null,"You are a Student");
}
}
//Displays the final U.S dollar amount for the user, which includes the additional 10% if greater than $100.00 dollars
JOptionPane.showMessageDialog(null,"The U.S Dollar amount for Mexican Peso conversion is: " + dollar);
break;

// case (Converting the Canadian Dollar currency to U.S. Dollars)
case 4:
String yen;
float yourrate3, percent3;
yen = JOptionPane.showInputDialog(null,"Enter amount of Japanese Yen currency to be converted to U.S Dollars");
yourrate3 = Float.parseFloat(yen); //Takes the user input of yen, and equates that to yourrate3
dollar = yourrate3/(float)0.0091; //Calculation that converts the currency into U.S. dollars
if (dollar > 100.00f){ /*If statement. If the conversion is greater than 100 U.S Dollars an additional 10% is granted.*/
percent3 = (float).10 * yourrate3; //10% calculation
dollar = percent3 + dollar; //calculation for adding the 10% to the final dollar amount
}
if (dollar > 200.00f){ //If Statement. Greater than 200 dollars a message appears, "You are Rich"
JOptionPane.showMessageDialog(null,"You are Rich");

}else{
if (dollar < 200.00f){ //If statement. Less than $200.00 dollars a message appears, "You are a student"
JOptionPane.showMessageDialog(null,"You are a Student");
}
}
//Displays the final U.S dollar amount for the user, which includes the additional 10% if greater than $100.00 dollars
JOptionPane.showMessageDialog(null,"The U.S Dollar amount for the Japanese Yen conversion is: " + dollar);
break;

// case (Converting the Swiss Franc currency to U.S. Dollars)
case 5:
String swiss;
float yourrate4, percent4;
swiss = JOptionPane.showInputDialog(null,"Enter amount of Swiss currency to be converted to U.S Dollar");
yourrate4 = Float.parseFloat(swiss); //Takes the user input of Swiss Franc, and equates that to yourrate4
dollar = yourrate4/(float)0.7278; //Calculation that converts the currency into U.S. dollars
if (dollar > 100.00f){ /*If statement. If the conversion is greater than 100 U.S Dollars an additional 10% is granted.*/
percent4 = (float).10 * yourrate4; //10% calculation
dollar = percent4 + dollar; //calculation for adding the 10% to the final dollar amount
}
if (dollar > 200.00f){ //If Statement. Greater than 200 dollars a message appears, "You are Rich"
JOptionPane.showMessageDialog(null,"You are Rich");

}else{
if (dollar < 200.00f){ //If statement. Less than $200.00 dollars a message appears, "You are a student"
JOptionPane.showMessageDialog(null,"You are a Student");
}
}
//Displays the final U.S dollar amount for the user, which includes the additional 10% if greater than $100.00 dollars
JOptionPane.showMessageDialog(null,"The U.S Dollar amount for the Swiss Franc conversion is: " + dollar);
break;

// case (Default case for error checking. If the user selects 6 or greater this message is displayed
default:
JOptionPane.showMessageDialog(null,"Invalid Entry, Please select items 1-5");
break; //break in the case to the next case if any
// End Case
}
}
System.exit(0);



}

}

With this I have gotten it down to 1 error. but still something is missing.
Error
int conversionChoice = getconversionChoice(); it is pointing a the symbols parenthesis.

Thanks in advance.

Phil Karras
11-19-2003, 10:40 AM
First, System.exit(0); should probably be removed since as soon as you hit this the program should exit to the system, and you say that's not what you want it to do.

Next,

import javax.swing.*;
public class thirdprogram { //Identifies the saved name of the program, secondprogram.java
private static final int EXIT_CHOICE = 9;

public static void main(String[] args){

tells me that this is a JAVA program, NOT a JavaScript program, which resides in an HTML or .js file. So, for the rest of your probelm you'll need to find a JAVA web site.

I believe there should be one on this site but as I said this is not it.

Good-luck.

fredmv
11-19-2003, 10:44 AM
That is Java code, this is a JavaScript forum. They are two entirely different languages.

Phil Karras
11-19-2003, 10:47 AM
Yes I told him that as well.

jbreedlove5
11-19-2003, 11:10 AM
This is java script/ programming and not intended to be used for a web page. What part makes it appear to be java web programming? I had received some assistance from the sun forum and that is why this portion is in there
private static final int EXIT_CHOICE = 9; public static void main(String[] args) { int conversionChoice = getConversionChoice(); while (conversionChoice != EXIT_CHOICE) { switch (conversionChoice) { // do stuff } conversionChoice = getConversionChoice(); } } public static int getConversionChoice() {

But I am unable to get it work. Any assistance you can offer will be appreciated.

Phil Karras
11-19-2003, 02:37 PM
import javax.swing.*;

This is a java library and has nothing to do with JavaScript.


public class thirdprogram { //Identifies the saved name of the program, secondprogram.java
private static final int EXIT_CHOICE = 9;

public static void main(String[] args){

This is the way one starts a Java program and again has nothing to do with JavaScript.

Also, note the comment:

//Identifies the saved name of the program, secondprogram.java

The extension says it all .java
QED This is a Java Program and has nothing to do with JavaScript!