jeudi 22 janvier 2015

CurrencyConversion (Java)

(MY if statements runs the whole thing instead of going through each one to find the right statement. EX: I type in Thai and it gives me all three results)


Given one of the three currencies, the program should convert the input amount into one of the other currencies. For example, if you input one (1) U.S. dollar, and you decide to convert that one dollar to a pound, then the output should be .60.


Using the JOptionPane GUI, do the following.


Prompt the user for the currency code type. Prompt the user for the amount of that currency. Prompt the user for the currency code that the entered amount must be converted to.


Using the table above, the following formula was used to convert USD to JPY.


10.00 * 103.73 = 1,037.30


Display the results in a JOptionPane message box.


My work


import javax.swing.JOptionPane;


public class CurrencyConversion {



public static void main(String[] args) {

int x = 0;
double result,result1, result2;
String THAI = "THAI", EURO ="EURO", JPY = "JPY";

String name = JOptionPane.showInputDialog("What is your name: ");
String message = String.format("Welcome %s, to the Currency Exchange Program ", name); /*inputs name in %s*/
JOptionPane.showMessageDialog(null, message); //displays the String format message
String currency = JOptionPane.showInputDialog("Which currency do you wish to exchange: "+THAI+ ", "+EURO+ ", "+JPY);
x = Integer.parseInt (JOptionPane.showInputDialog("Insert US Dollar Amount: "));
result = x * 32.57; //US TO THAI
result1 = x * .86; //US TO EURO
result2 = x * 117.50; //US TO JPY


if (THAI == "THAI")
JOptionPane.showMessageDialog(null,"US Dollar Amount of "+x+ " dollars to be converted to "+THAI+" is: ");
JOptionPane.showMessageDialog(null,result+ " BAHT");
if (EURO == "EURO")
JOptionPane.showMessageDialog(null,"The Amount of "+x+ " dollars to be converted to "+EURO+" is: ");
JOptionPane.showMessageDialog(null,result1+ " EURO");
if (JPY == "JPY")
JOptionPane.showMessageDialog(null,"The Amount of "+x+ " dollars to be converted to "+JPY+" is: ");
JOptionPane.showMessageDialog(null,result2+ " JPY");
//end THAI if


}//end main


}//end class


Aucun commentaire:

Enregistrer un commentaire