IPetrov007

Calculator new

Oct 3rd, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.text.Format;
  2. import java.util.Scanner;
  3.  
  4. /**
  5. * Created by Ivan Petrov on 10/2/2016.
  6. */
  7. public class p12_Calculator {
  8. public static void main(String[] args) {
  9. Scanner console = new Scanner(System.in);
  10.  
  11. double BGN = 1;
  12. double USD = 1.79549;
  13. double EUR = 1.95583;
  14. double GBP = 2.53405;
  15. double result = 0;
  16.  
  17. double amaunt = Double.parseDouble(console.nextLine());
  18. String inCurrency = console.nextLine();
  19. String outCurrency = console.nextLine();
  20.  
  21. if (inCurrency.equalsIgnoreCase("GBP")) {
  22. BGN = GBP * amaunt;
  23. } else if (inCurrency.equalsIgnoreCase("EUR")){
  24. BGN = EUR * amaunt;
  25. } else if (inCurrency.equalsIgnoreCase("USD")){
  26. BGN = USD * amaunt;
  27. } else if (inCurrency.equalsIgnoreCase("BGN")){
  28. BGN = amaunt;
  29. } else System.out.println("Wrong currency");
  30.  
  31. if (outCurrency.equalsIgnoreCase("GBP")) {
  32. result = BGN / GBP;
  33. } else if (outCurrency.equalsIgnoreCase("EUR")){
  34. result = BGN / EUR;
  35. } else if (outCurrency.equalsIgnoreCase("USD")) {
  36. result = BGN / USD;
  37. } else if (outCurrency.equalsIgnoreCase("BGN")) {
  38. result = BGN;
  39. } else System.out.println("Wrong currency");
  40.  
  41. String newresult = String.format("%.2f", result);
  42. System.out.printf("Result is %s %s", newresult, outCurrency);
  43. }
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment