All pastes #1035683 Raw Edit

if/else

public text v1 · immutable
#1035683 ·published 2008-06-01 07:50 UTC
rendered paste body
//Josh Day
//Lab #4
//Completed 5.31.2008

import java.util.Scanner;
import java.text.*;

public class Lab4ACurrency
{
	public static void main(String[]args)
	{
	  int n;
	  double x;
	  double y;
	  double dollars;
	  double CAN = 0.992299754;
	  double MEX = 10.3117234;
	  double JAP = 105.296409;
	  double EUR = 0.643293664;
	  
	Scanner read = new Scanner(System.in);
	  
	  System.out.println("\nForeign Exchange\n");
	  System.out.println("1. U.S. to Canada");
	  System.out.println("2. U.S. to Mexico");
	  System.out.println("3. U.S. to Japan");
	  System.out.println("4. U.S. to Euro");
	  System.out.println("0. Quit\n");
	  System.out.print("Enter your choice: ");
	  
	  n = read.nextInt();
	  
	  {
	    if ( n == 0 )  
	    {
		   return;
		 }
	    if ( n > 4 )
	    {
	      System.out.print("You've entered an invalid choice. Please run the program again.");
	      return;
	    }
	  }
	  
	  System.out.print("\nInput you desired Dollar amount, then press Enter: ");
	  
	  dollars = read.nextDouble();
	  
	  x = 0;
	  y = 0;
	  String curr = "";
	  
	  {
 	    if ( n == 1 )
	    {
	      y = CAN;
	      x = dollars * CAN;
		   curr = "Canadian Dollars";
	    }
	    if ( n == 2 )
	    {
	      y = MEX;
	     x = dollars * MEX;
		   curr = "Pesos";
	    }
	    if ( n == 3 )
	    {
	      y = JAP;
	      x = dollars * JAP;
		   curr = "Yen";
	    }
	    if ( n == 4 )
	    {
	      y = EUR;
	      x = dollars * EUR;
		   curr = "Euros";
	    }
	  }
	  
	  
	  DecimalFormat decimal = new DecimalFormat("###,##0.00");
     DecimalFormat money = new DecimalFormat("$###,##0.00");
	  
	  System.out.println("\nYou entered " + money.format(dollars) + " US Dollars.");
	  System.out.println("The conversion rate is " + decimal.format(y) + " " + curr + " for $1.00.");
	  System.out.println("That equals " + decimal.format(x) + " " + curr + ".");
	  
	}
}