ELET 2300 Programming Assignment # 1 Spring 2018 Due: 3/21 Before 11:50 PM Write
ID: 3734000 • Letter: E
Question
ELET 2300 Programming Assignment # 1 Spring 2018 Due: 3/21 Before 11:50 PM Write a program that operates a currency conversion between US Dollars (USD) and EURO (EUR). Immediately after execution, the program asks the user to select which conversion is desired: Options: : USD-> EUR 2: EUR->USD Please select an option: After selection, the program asks the user to insert the conversion factor from EUR to USD (e.g. 1 EUR-1.4 USD). Finally, the program converts and displays (in a tabular form) the first ten amounts (1-10 USD or 1-10 EUR) into the destination currency, using the conversion factor provided by the user. Options: 1: USD-> EUR 2: EUR- >USD Please select an option: 2 Please insert the conversion factor (EUR->USD): 1.4Explanation / Answer
package org.students;
import java.util.Scanner;
public class CurrencyConversion {
public static void main(String[] args) {
// Declaring variables
int choice;
double conversionFactor;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
//displaying the menu
System.out.println("Options:");
System.out.println("1.USD -> EUR");
System.out.println("2.EUR -> USD");
//getting the choice entered by the user
System.out.print(" Please select an option:");
choice = sc.nextInt();
//Based on the user choice the corresponding case will be executed
switch (choice) {
case 1:
{
System.out.print(" Please insert the conversion factor (USD -> EUR):");
conversionFactor = sc.nextDouble();
System.out.println("USD EUR");
System.out.println("--- ----");
for (int i = 1; i <= 10; i++) {
System.out.printf("%d %.1f ", i, i * conversionFactor);
}
break;
}
case 2:
{
System.out.print(" Please insert the conversion factor (EUR -> USD):");
conversionFactor = sc.nextDouble();
System.out.println("EUR USD");
System.out.println("--- ----");
for (int i = 1; i <= 10; i++) {
System.out.printf("%d %.1f ", i, i * conversionFactor);
}
break;
}
default:
{
System.out.println("** Invalid Choice **");
break;
}
}
}
}
__________________
Output:
Options:
1.USD -> EUR
2.EUR -> USD
Please select an option:2
Please insert the conversion factor (EUR -> USD):1.4
EUR USD
--- ----
1 1.4
2 2.8
3 4.2
4 5.6
5 7.0
6 8.4
7 9.8
8 11.2
9 12.6
10 14.0
____________Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.