Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

USD exchange for Mexican Peso

807599Jan 25 2007 — edited Jan 25 2007
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 );
		}
	}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 22 2007
Added on Jan 25 2007
38 comments
1,070 views