From c24e8f1931d19b49a215bc50365c9b29a407b31a Mon Sep 17 00:00:00 2001 From: Piotr Baranowski Date: Wed, 10 Jun 2020 13:11:33 +0200 Subject: [PATCH] =?UTF-8?q?p=C4=99tla=20w=20main,=20kurs=200=20dla=20b?= =?UTF-8?q?=C5=82=C4=99dnych=20kod=C3=B3w=20walut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Main.java | 19 ++++++++++++++++++- src/main/java/RatesProcessing.java | 7 ++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 0c770d7..3b47b18 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -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; + } + } } } diff --git a/src/main/java/RatesProcessing.java b/src/main/java/RatesProcessing.java index 6f0b55d..2affb54 100644 --- a/src/main/java/RatesProcessing.java +++ b/src/main/java/RatesProcessing.java @@ -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); + } } }