pętla w main, kurs 0 dla błędnych kodów walut
This commit is contained in:
parent
b048d12e95
commit
c24e8f1931
|
@ -1,6 +1,23 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
EcbApi getRates = new EcbApi();
|
||||
System.out.println(getRates.exchangeRate("PLN"));
|
||||
|
||||
String continuteInput;
|
||||
Scanner read = new Scanner(System.in);
|
||||
|
||||
while(true) {
|
||||
System.out.print("Podaj trzyliterowy kod waluty: ");
|
||||
String currencyCode = read.nextLine();
|
||||
|
||||
System.out.println("Kurs EUR/" + currencyCode + " wynosi " + getRates.exchangeRate(currencyCode));
|
||||
|
||||
System.out.print("Czy chcesz sprawdzić kurs kolejnej waluty? [t/n] ");
|
||||
continuteInput = read.nextLine();
|
||||
if(continuteInput.equals("n")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,11 @@ public class RatesProcessing {
|
|||
}
|
||||
|
||||
public BigDecimal getRate(String currencyCode) {
|
||||
return rates.get(currencyCode);
|
||||
if(rates.containsKey(currencyCode)) {
|
||||
return rates.get(currencyCode);
|
||||
}
|
||||
else {
|
||||
return BigDecimal.valueOf(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue