Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * Created by Raly on 21.12.2016 г..
- */
- public class CurrencyConvertor {
- public static void main(String[] args) {
- Scanner reader = new Scanner(System.in);
- // System.out.println(); // sout
- // System.out.printf("%s", "foo"); // souf
- System.out.print("Enter number: ");
- double inputMoney = Double.parseDouble(reader.nextLine());
- System.out.print("Enter input currency: ");
- String inputCurrency = reader.nextLine();
- System.out.print("Enter output currency: ");
- String outputCurrency = reader.nextLine();
- double bgnUsd = 1.79549;
- double bgnEur = 1.95583;
- double bgnGbp = 2.53405;
- double vInBgn = 1.0;
- double output = 1.0;
- // 1 step -> convert input amount money in leva
- if (inputCurrency.equals("USD")){
- vInBgn = inputMoney * bgnUsd;
- }
- else if(inputCurrency.equals("EUR")){
- vInBgn = inputMoney * bgnEur;
- }
- else if(inputCurrency.equals("GBP")){
- vInBgn = inputMoney * bgnGbp;
- }
- else if (inputCurrency.equals("BGN")){
- vInBgn = inputMoney;
- }
- else{
- System.out.println("Invalid input");
- }
- // 2 step -> convert into output currency
- if (outputCurrency.equals("USD")){
- output = vInBgn / bgnUsd;
- }
- else if(outputCurrency.equals("EUR")){
- output = vInBgn / bgnEur;
- }
- else if (outputCurrency.equals("GBP")){
- output = vInBgn / bgnGbp;
- }
- else if (outputCurrency.equals("BGN")){
- output = vInBgn;
- }
- else{
- System.out.println("Invalid input");
- }
- System.out.printf("%.2f %s", output, outputCurrency);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement