Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. Scanner s = new Scanner(System.in);
  2. double amount;
  3. String from, to;
  4.  
  5. double usdToBgn = 1.72;
  6. double eurtobgn = 1.9558;
  7. System.out.print("Amount: ");
  8. amount = s.nextDouble();
  9. System.out.print("From: ");
  10. from = s.next();
  11. System.out.print("To: ");
  12. to = s.next();
  13.  
  14. double result;
  15. if (from.equals(to)) {
  16. result = amount;
  17. } else if (from.equals("USD") && to.equals("BGN")) {
  18. result = amount * usdToBgn;
  19. } else if (from.equals("USD") && to.equals("EUR")) {
  20. result = amount * usdToBgn / eurtobgn;
  21. } else if (from.equals("BGN") && to.equals("USD")) {
  22. result = amount / usdToBgn;
  23. } else if (from.equals("BGN") && to.equals("EUR")) {
  24. result = amount / eurtobgn;
  25. } else if (from.equals("EUR") && to.equals("BGN")) {
  26. result = amount * eurtobgn;
  27. } else if (from.equals("EUR") && to.equals("USD")) {
  28. result = amount * eurtobgn / usdToBgn;
  29.  
  30. } else {
  31. System.out.println("Unknown conversion");
  32. return;
  33. }
  34. System.out.printf("Result: %.4f\n", result);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement