My friend is going to Mexico this spring break and so I am trying to write a program that converts United Stated Dollars into Mexican Pesos. The program should ask the user (my friend) to input how many USD he would like to exchange for Mexican Pesos. I know there are 1000-peso note, 500-peso notes, 200-peso notes, 100-peso note, 50-peso notes, and 20-peso notes. If he receives a total of 1600 Mexican pesos, I would like the program to state the total as: 1 1000-peso note, 1 500-peso note, 0, 200-peso notes, 1 100-peso note, 0 50-peso notes, and 0 20-peso notes. But it would not tell him 80 20-peso notes. I have found out the exchange rate for $1 USD to Mexican pesos, but I am unsure of how I would state how many Pesos he would receive in what denominations. Also, the program would tell him his change due back in US dollars or cents (since banks only have 20 and up denominations).
So far I have:
//
// Purpose: random program testing
// Author: James Doyle
//
import javax.swing.JOptionPane; // Needed for JOptionPane Class
import java.text.DecimalFormat; // Needed for DecimalFormat Class
public class random
{
public static void main( String[] args ){
double unitedStatesDollars; // Amount of money in USD
final double EXCHANGERATE = 10.9487; // Current exchange rate for $1 USD to Mexican pesos
String input; // To hold the user's input
// Create a DecimalFormat object for dollar amounts.
DecimalFormat dollar = new DecimalFormat("#.00");
// Hold the amount of money that the user inputs
input = JOptionPane.showInputDialog("Please enter the amount of money, " +
"in United States Dollars, that you " +
"would like to convert to Mexican Pesos.");
unitedStatesDollars = Integer.parseInt(input);
double mexicanPeso = unitedStatesDollars * EXCHANGERATE;
JOptionPane.showMessageDialog(null, "You will receive " + mexicanPeso +
" in Mexican Pesos in echange for $" +
dollar.format(unitedStatesDollars));
System.exit( 0 );
}
}