Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. import java.util.*;
  2. import java.text.DecimalFormat;
  3.  
  4. public class currencyconverter {
  5.  
  6. public static void main(String[] args) {
  7. DecimalFormat f = new DecimalFormat("##.##");
  8. Scanner myObj = new Scanner(System.in);
  9. System.out.println("Hoi! Welkom bij het eerste 'officiële' script van Dyon Heintjes - Hogeschool NOVI.");
  10. System.out.println("Met deze tool kun je de volgende valuta converteren: EUR, USD, en GBP.");
  11. System.out.println("Welke van de bovenstaande valuta wil je converteren?");
  12. String valuta1 = myObj.nextLine();
  13. System.out.println("Je hebt gekozen voor " + valuta1.toUpperCase() + ".");
  14. System.out.println("Hoeveel " + valuta1.toUpperCase() + " wil je converteren?");
  15. double aantal = myObj.nextDouble();
  16.  
  17. // Skip the newline
  18. myObj.nextLine();
  19.  
  20. System.out.println("Naar welke valuta wil je " + f.format(aantal) + " " + valuta1.toUpperCase() + " converteren?");
  21. String valuta2 = myObj.nextLine();
  22.  
  23. conversie(valuta1.toUpperCase(), valuta2.toUpperCase(), aantal);
  24. }
  25.  
  26. static void conversie(String valuta1, String valuta2, double aantal) {
  27. try {
  28. DecimalFormat f = new DecimalFormat("##.##");
  29. switch (valuta1.toUpperCase()) {
  30. case "EUR":
  31. if (valuta2.equals("EUR")) {
  32. double conversie = aantal * 1;
  33. System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
  34. } else if (valuta2.equals("USD")) {
  35. double conversie = aantal * 1.10;
  36. System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
  37. } else if (valuta2.equals("GBP")) {
  38. double conversie = aantal * 0.86;
  39. System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
  40. } else System.out.println("shit");
  41. { //TODO BIJ VERKEERDE INPUT NOG EEN JUISTE OUTPUT AANWIJZEN!
  42. }
  43. break;
  44. case "USD":
  45. if (valuta2.equals("USD")) {
  46. double conversie = aantal * 1;
  47. System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
  48. } else if (valuta2.equals("EUR")) {
  49. double conversie = aantal * 0.91;
  50. System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
  51. } else if (valuta2.equals("GBP")) {
  52. double conversie = aantal * 0.78;
  53. System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
  54. } else System.out.println("shit");
  55. { //TODO BIJ VERKEERDE INPUT NOG EEN JUISTE OUTPUT AANWIJZEN!
  56. }
  57. break;
  58. case "GBP":
  59. if (valuta2.equals("GBP")) {
  60. double conversie = aantal * 1;
  61. System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
  62. } else if (valuta2.equals("USD")) {
  63. double conversie = aantal * 1.29;
  64. System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
  65. } else if (valuta2.equals("EUR")) {
  66. double conversie = aantal * 1.17;
  67. System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
  68. } else System.out.println("shit");
  69. { //TODO BIJ VERKEERDE INPUT NOG EEN JUISTE OUTPUT AANWIJZEN!
  70. }
  71. break;
  72. default:
  73. }
  74. throw new IllegalStateException("Unexpected value: " + valuta1.toUpperCase());
  75. } catch (Exception e){
  76. System.out.println("Error!");
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement