In: Computer Science
You are tasked with developing an application that
converts US currency ($) to 3 other major world
currencies.
Here are the current rates:
1 US dollar = 0.90 EURO
1 US dollar = 107.7 Japanese YEN
1 US dollar =19.45 Mexican PESO
Your application must prompt the user to enter an
amount in US dollars, convert it into EURO, YES, and PESO and then
display all using a suitable format.
Coding requirements:
-All your variables MUST declared inside main()
except for the Scanner.
-Code function(s)/method(s) that handle
all input.
-Code function(s)/method(s) that handles all
conversions.
-Code a function/method that displays the result of
the conversion. Your output must be clear and well
labeled.
(show the amount input in dollar, then show the amount
of the conversion for each of the three major currencies)
//import the Scanner class to create an object to the read the
data from the user.
import java.util.Scanner;
// main class name is converion
public class Conversion {
//creating an object for Scanner class .
//Scanner object has to be static.
//In java a static method can call only static methods.
static Scanner sc = new Scanner(System.in);
//driver code.
public static void main(String args[]) {
//asking the user to enter the
amount in dollrs
System.out.println("Enter the
amount in dollars : ");
//taking the input from the user
using the sc (Scanner class) object
double Dollars =
sc.nextDouble();
//displaying the user entered
amount
System.out.println("Entered amount
in dollars is :"+Dollars+"$");
System.out.println("Currency after
conversion");
//converting the currency into
other countries currencies.
//inorder to convert from one
currency to another we multiply with the value with which they are
in proportion.
//incase of Euros it is 1 US Dollar
= 0.90 Euro
double Euros = Dollars *
0.90;
// printing the amount in
Euros
System.out.println("Amount in
Euros: "+ Euros);
//1 US Dollar = 107.7 Yen
double Yen = Dollars * 107.7;
//printing the amount in Yen
System.out.println("Amount in Yen :
"+ Yen);
// 1 US dollar = 19.45 Peso
double Peso = Dollars *
19.45;
//printing the amoun in Peso
System.out.println("Amount in Peso
: "+ Peso);
}
}
OUTPUT: -