CurrencyConverter.java 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import java.util.Scanner;
  2. public class CurrencyConverter {
  3. public double convertCurrency(double currency1, double currency2, double amount) {
  4. double converted = (currency2 * amount)/ currency1; //converts to currency2
  5. return converted;
  6. }
  7. public double getStringInput(String prompt) {
  8. double userSelection = 0;
  9. while(userSelection == 0){
  10. Scanner scanner = new Scanner(System.in);
  11. System.out.println(prompt);
  12. String userInput = scanner.nextLine();
  13. switch(userInput){
  14. case "us dollar" : userSelection = 1.00;
  15. break;
  16. case "euro" : userSelection = 0.94;
  17. break;
  18. case "british pound" : userSelection = 0.82;
  19. break;
  20. case "indian rupee" : userSelection = 68.32;
  21. break;
  22. case "australian dollar" : userSelection = 1.35;
  23. break;
  24. case "canadian dollar" : userSelection = 1.32;
  25. break;
  26. case "singapore dollar" : userSelection = 1.43;
  27. break;
  28. case "swiss franc" : userSelection = 1.01;
  29. break;
  30. case "malaysian ringgit" : userSelection = 4.47;
  31. break;
  32. case "japanese yen" : userSelection = 115.84;
  33. break;
  34. case "chinese yuan renminbi" : userSelection = 6.92;
  35. break;
  36. default : System.out.println("That money ain't nothin' to #$%& with");
  37. System.out.println("Choose a some money we can work with!");
  38. break;
  39. }
  40. }
  41. return userSelection;
  42. }
  43. public double getDoubleInput(String prompt) {
  44. Scanner scannerB = new Scanner(System.in);
  45. double b = 0;
  46. System.out.println(prompt);
  47. while(b == 0){
  48. if(scannerB.hasNextDouble()){
  49. b = scannerB.nextDouble();
  50. }else{
  51. System.out.println("Invalid input please choose a number greater than 0\n");
  52. }
  53. }
  54. return b;
  55. }
  56. }