forked from carstenfuhs-bbk/currency-exchanger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
currencyConverter.groovy
37 lines (36 loc) · 1.29 KB
/
currencyConverter.groovy
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
print "If I give you £1, how many Euro will you give me? ";
double euroOverPoundRatio = Double.parseDouble(System.console().readLine());
print "If I give you 1€, how many Sterling pounds will you give me? ";
double poundOverEuroRatio = Double.parseDouble(System.console().readLine());
println "OK, now I know enough.";
boolean finished = false;
while (!finished) {
println "";
println "What would you like to do?";
println " 1 - Exchange pounds into euro";
println " 2 - Exchange euro into pounds";
println " 0 - Exit the program";
println "";
print "> ";
int choice = Integer.parseInt(System.console().readLine());
switch (choice) {
case 1:
print "How many pounds would you like to convert? ";
double pounds = Double.parseDouble(System.console().readLine());
double euro = pounds * euroOverPoundRatio;
println "£" + pounds + " will give you " + euro + "€";
break;
case 2:
print "How many euro would you like to convert? ";
double euro = Double.parseDouble(System.console().readLine());
double pounds = euro * poundOverEuroRatio;
println euro + "€ will give you £" + pounds;
break;
case 0:
finished = true;
break;
default:
println "Sorry, that is not a valid option";
}
}
println "Exiting the program";