-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.java
More file actions
47 lines (36 loc) · 1.38 KB
/
Console.java
File metadata and controls
47 lines (36 loc) · 1.38 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
package currencyExchange;
import java.util.Scanner;
public class Console {
String IFO;
String totalSTR;
int total;
double totalConverted;
Scanner reader = new Scanner(System.in);
// a method, which reads the currency.
void readCurrency() {
// read the value if currecy base matches..
while (totalConverted != -1) {
// read the currency.
System.out.print("Wrtie a currency, and I will convert to USD: ");
IFO = reader.nextLine();
System.out.print("Write the value: ");
totalSTR = reader.nextLine();
// convert to USD.
try {
total = Integer.parseInt(totalSTR);
totalConverted = Exchanger.exchangeToUSD(IFO, total);
// show the result if currency matches.
if (totalConverted != -1) {
System.out.println(total + " of " + IFO +
" in USD is $" + totalConverted);
break;
} else {
System.out.println("Please write on next session the currency" +
"which matches in the given base");
}
} catch (NumberFormatException exc) {
System.out.println("Please write");
}
}
}
}