import javax.swing.JOptionPane; public class program7 { public static void main(String[] args) { //ask user how many euros a dollar buys String euroExchangeRateString = JOptionPane.showInputDialog (null, "Enter how many Euros one Dollar will buy"); double euroExchangeRate = Double.parseDouble(euroExchangeRateString); //ask user how many pounds a dollar will buy String poundExchangeRateString = JOptionPane.showInputDialog (null, "Enter how many Pounds one Dollar will buy"); double poundExchangeRate = Double.parseDouble(poundExchangeRateString); //ask user how many yen a dollar will buy String yenExchangeRateString = JOptionPane.showInputDialog (null, "Enter how many Yen one Dollar will buy"); double yenExchangeRate = Double.parseDouble(yenExchangeRateString); //ask user to enter the number of dollars they have String amountDollarsString = JOptionPane.showInputDialog (null, "Enter the amount of foreign currency you want to buy in U.S. dollars"); double amountDollars = Double.parseDouble(amountDollarsString); if (amountDollars <= 100){ amountDollars -= amountDollars * 0.10; JOptionPane.showMessageDialog (null,"You can buy $" + amountDollars + " in foreign currency."); } else if (amountDollars > 100) { amountDollars -= amountDollars * 0.05; JOptionPane.showMessageDialog (null,"You can buy $" + amountDollars + " in foreign currency."); } String reply = JOptionPane.showInputDialog (null, "Enter 'E' to buy Euros, 'P' to buy Punds or 'Y' to buy Yen"); char firstChar = reply.charAt(0); while (firstChar == 'E' || firstChar == 'e'){ double amountEuros = (amountDollars * euroExchangeRate); JOptionPane.showMessageDialog (null, "You have purchased " + amountEuros + " Euros."); } if (firstChar == 'P' || firstChar == 'p') { double amountPounds = (amountDollars * poundExchangeRate); JOptionPane.showMessageDialog (null, "You have purchased " + amountPounds + " Pounds."); } else if (firstChar == 'Y' || firstChar == 'y') { double amountYen = (amountDollars * yenExchangeRate); JOptionPane.showMessageDialog (null, "You have purchased " + amountYen + " Yen."); } JOptionPane.showConfirmDialog (null, "Are there any more conversions you would like to perform?"); } }
On the last part, the program is supposed to ask the user if there are anymore conversions to perform. I put in a confirm dialog box, but when the user clicks yes it does not go back to repeat the previous loop. How can I make it do that?