Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.text.DecimalFormat;
- public class currencyconverter {
- public static void main(String[] args) {
- DecimalFormat f = new DecimalFormat("##.##");
- Scanner myObj = new Scanner(System.in);
- System.out.println("Hoi! Welkom bij het eerste 'officiële' script van Dyon Heintjes - Hogeschool NOVI.");
- System.out.println("Met deze tool kun je de volgende valuta converteren: EUR, USD, en GBP.");
- System.out.println("Welke van de bovenstaande valuta wil je converteren?");
- String valuta1 = myObj.nextLine();
- System.out.println("Je hebt gekozen voor " + valuta1.toUpperCase() + ".");
- System.out.println("Hoeveel " + valuta1.toUpperCase() + " wil je converteren?");
- double aantal = myObj.nextDouble();
- // Skip the newline
- myObj.nextLine();
- System.out.println("Naar welke valuta wil je " + f.format(aantal) + " " + valuta1.toUpperCase() + " converteren?");
- String valuta2 = myObj.nextLine();
- conversie(valuta1.toUpperCase(), valuta2.toUpperCase(), aantal);
- }
- static void conversie(String valuta1, String valuta2, double aantal) {
- try {
- DecimalFormat f = new DecimalFormat("##.##");
- switch (valuta1.toUpperCase()) {
- case "EUR":
- if (valuta2.equals("EUR")) {
- double conversie = aantal * 1;
- System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
- } else if (valuta2.equals("USD")) {
- double conversie = aantal * 1.10;
- System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
- } else if (valuta2.equals("GBP")) {
- double conversie = aantal * 0.86;
- System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
- } else System.out.println("shit");
- { //TODO BIJ VERKEERDE INPUT NOG EEN JUISTE OUTPUT AANWIJZEN!
- }
- break;
- case "USD":
- if (valuta2.equals("USD")) {
- double conversie = aantal * 1;
- System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
- } else if (valuta2.equals("EUR")) {
- double conversie = aantal * 0.91;
- System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
- } else if (valuta2.equals("GBP")) {
- double conversie = aantal * 0.78;
- System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
- } else System.out.println("shit");
- { //TODO BIJ VERKEERDE INPUT NOG EEN JUISTE OUTPUT AANWIJZEN!
- }
- break;
- case "GBP":
- if (valuta2.equals("GBP")) {
- double conversie = aantal * 1;
- System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
- } else if (valuta2.equals("USD")) {
- double conversie = aantal * 1.29;
- System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
- } else if (valuta2.equals("EUR")) {
- double conversie = aantal * 1.17;
- System.out.println(f.format(aantal) + " " + valuta1.toUpperCase() + " omgerekend naar " + valuta2.toUpperCase() + " komt uit op " + f.format(conversie) + " " + valuta2.toUpperCase());
- } else System.out.println("shit");
- { //TODO BIJ VERKEERDE INPUT NOG EEN JUISTE OUTPUT AANWIJZEN!
- }
- break;
- default:
- }
- throw new IllegalStateException("Unexpected value: " + valuta1.toUpperCase());
- } catch (Exception e){
- System.out.println("Error!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement