-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExchangeRates.java
More file actions
69 lines (54 loc) · 2.25 KB
/
Copy pathExchangeRates.java
File metadata and controls
69 lines (54 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.InputMismatchException;
import java.util.Scanner;
public class ExchangeRates {
public static CurrencyConverter converter;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
CurrencyConverter converter = new CurrencyConverter();
boolean flag = true;
System.out.println("==============================");
System.out.println("| PHP Exchange rates program |");
System.out.println("==============================");
while(flag){
char choice;
try{
System.out.print("Enter the amount in PHP: ");
double amountPHP = in.nextDouble();
in.nextLine();
converter.printCurrencies();
System.out.println("-------------------------------------------------");
System.out.print("Choose a currency: ");
System.out.println("(Type the currency to convert)");
System.out.println("-------------------------------------------------");
String targetCurrency = in.nextLine();
double convertedAmount = converter.convert(amountPHP, "PHP", targetCurrency);
if (convertedAmount != -1.0) {
System.out.println("=================================================");
System.out.println("Entered amount: " + amountPHP + " PHP");
System.out.println("Converted amount: " + convertedAmount + " " + targetCurrency.toUpperCase());
System.out.println("=================================================");
}
}catch (InputMismatchException e){
System.out.println("Invalid Input");
break;
}
System.out.println("\nConvert again?");
System.out.print("(Y/N): ");
choice = in.next().toUpperCase().charAt(0);
switch(choice){
case 'N':
System.out.println("Program Exit...");
flag = false;
break;
case 'Y':
System.out.println("");
continue;
default:
System.out.println("Invalid Input\nTerminating Program...");
flag = false;
break;
}
}
in.close();
}
}