Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P6 {
  4. public static double euroRate, poundRate, yenRate, dollars, finalDollars;
  5. public static Scanner input = new Scanner(System.in);
  6.  
  7. public static void main (String[] args)
  8. {
  9. euroRate = getDoubleValue("Euro Rate: ");
  10. poundRate = getDoubleValue("Pound Sterling Rate: ");
  11. yenRate = getDoubleValue("Yen Rate: ");
  12.  
  13. do
  14. {
  15. dollars = getDoubleValue("Please enter the number of dollars you want to convert");
  16. printValues("Enter \"E\" to buy Euros, \"P\" to buy Pounds or \"Y\" to buy Yen");
  17. }
  18. while (continueConv("Are there more conversions to perform?"));
  19. }
  20.  
  21. private static void printValues(String prompt)
  22. {
  23. while(true)
  24. {
  25. System.out.println(prompt);
  26. char c = input.next().toLowerCase().charAt(0);
  27. double fee = getFee(dollars);
  28.  
  29. switch(c)
  30. {
  31. case 'e':
  32. finalDollars = conversion(euroRate, dollars, fee);
  33. System.out.println(dollars + " dollars = " + finalDollars + " euros");
  34. return;
  35. case 'p':
  36. finalDollars = conversion(poundRate, dollars, fee);
  37. System.out.println(dollars + " dollars = " + finalDollars + " pound sterlings");
  38. return;
  39. case 'y':
  40. finalDollars = conversion(yenRate, dollars, fee);
  41. System.out.println(dollars + " dollars = " + finalDollars + " yens");
  42. return;
  43. }
  44. }
  45. }
  46.  
  47. private static boolean continueConv(String prompt)
  48. {
  49. do
  50. {
  51. System.out.println(prompt);
  52. String s = input.nextLine();
  53.  
  54. switch(s.toLowerCase())
  55. {
  56. case "yes":
  57. return true;
  58. case "no":
  59. return false;
  60. }
  61. }
  62. while(true);
  63. }
  64.  
  65. private static double getFee (double dollars)
  66. {
  67. return (dollars > 100) ? 0.05 : 0.1;
  68. }
  69.  
  70. private static double conversion(double rate, double value, double feePercent)
  71. {
  72. double fConversion = (value * rate);
  73. return fConversion - (fConversion * feePercent);
  74. }
  75.  
  76. private static double getDoubleValue(String prompt)
  77. {
  78. System.out.println(prompt);
  79. return input.nextDouble();
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement