Вы находитесь на странице: 1из 7

currencyConverter.

java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Question1;

/**
*
* @author Nasuha
*/
public class CurrencyConverter {

private String fromCurrency;


private String toCurrency;
private double conversionValue;
private double convertedValue;

public CurrencyConverter(String fromCurrency, String toCurrency, int conversionValue) {


this.fromCurrency = fromCurrency;
this.toCurrency = toCurrency;
this.conversionValue = conversionValue;
}
public double convertValue(double convertedValue) {
return convertedValue;
}
public double setConvertedValue(double convertedValue) {
this.convertedValue = convertedValue;
return convertedValue;
}
public double currencyConvert(double newConvertValue) {
int choose, choose2;
double x, y, z;
double conversionAmount;
double rm = 4.73950;
double euro = 0.210993;
double rupiah = 3509.79;

return newConvertValue;
}
public void displayInfo() {
System.out.println("RM Value : ");
System.out.println("Euro Value : ");
System.out.println("Indonesian Rupiah Value : ");
}
}

testCurrencyConverter.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Question1;

import java.util.Scanner;

/**
*
* @author Nasuha
*/
public class TestCurrencyConverter {
public static void main(String arg[]) {

Scanner scan = new Scanner(System.in);

System.out.println("CURRENCY CONVERTER");
System.out.println("----------------------------------------");
System.out.println("Choose currency to be converted");
System.out.print("FROM [1:Ringgit Malaysia 2:Euro 3:Indonesian Rupiah] : ");
int choice = scan.nextInt();

String inType = null;


switch (choice) {
case 1:
inType = "RM";
break;
case 2:
inType = "Euro";
break;
case 3:
inType = "Rupiah";
default:
System.out.print("Choose again");
}
System.out.print("TO [1:Ringgit Malaysia 2:Euro 3:Indonesian Rupiah] : ");
int choice2 = scan.nextInt();
String inType1 = null;
switch (choice2) {
case 1:
inType1 = "RM";
break;
case 2:
inType1 = "Euro";
break;
case 3:
inType1 = "Rupiah";
default:
System.out.println("Choose again");
}
System.out.print("Enter the conversion amount : ");
double conversionValue = scan.nextDouble();

if (choice == 1 && choice2 == 1) {


System.out.println("----------------------------------------");
System.out.print("SAME CURRENCY!");
}
if (choice == 1 && choice2 == 2) {
double euro = 0.210993;
double rate = conversionValue * euro;
System.out.println("----------------------------------------");
System.out.printf("Currency converted : %.4f ", rate);
}
if (choice == 1 && choice2 == 3) {
double rupiah = 3509.79;
double rate = conversionValue * rupiah;
System.out.println("----------------------------------------");
System.out.printf("Currency converted : %.4f ", rate);
}
if (choice == 2 && choice2 == 1) {
double rm = 4.73950;
double rate = conversionValue * rm;
System.out.println("----------------------------------------");
System.out.printf("Currency converted : %.4f ", rate);
}
if (choice == 2 && choice2 == 2) {
System.out.println("----------------------------------------");
System.out.print("SAME CURRENCY!");
}
if (choice == 2 && choice2 == 3) {
double rupiah = 3509.79;
double rate = conversionValue * rupiah;
System.out.println("----------------------------------------");
System.out.printf("Currency converted : %.4f ", rate);
}
if (choice == 3 && choice2 == 1) {
double rm = 4.73950;
double rate = conversionValue * rm;
System.out.println("----------------------------------------");
System.out.printf("Currency converted : %.4f ", rate);
}
if (choice == 3 && choice2 == 2) {
double euro = 0.210993;
double rate = conversionValue * euro;
System.out.println("----------------------------------------");
System.out.printf("Currency converted : %.4f ", rate);
}
if (choice == 3 && choice2 == 3) {
System.out.println("----------------------------------------");
System.out.print("SAME CURRENCY");
}
}
}

Output

Вам также может понравиться