In: Computer Science
Using the object-oriented programming principles, write a currency exchange converter in Java. You should also use 3 different classes it could be currency1 and currency2 and currencytest, and set() and get() method and tostring() method. A person will be presented with 3 currencies (i.e., USD, AED, MYR) that they can convert to/from AED Dirham. The program will allow the user to input the amount of Dirham or other currency to be converted. The Money changer will take AED50 commission if converted amount is equal or more than AED900, or it will take AED10 commission if the converted amount is less than that.
Your program should throw an error message if the user tries to convert an amount less than AED30.
Note: 1 AED=0.27 USD, 1 AED=1.14 MYR
Sample output:
Please enter your currency (USD, AED, or MYR only): USD
What currency do you want?: AED
How much you want to convert? : 1000
Thank you. The converted amount is AED3673.20. We will take AED50 commission, and you will get 3623.20.
Please enter your currency (USD, AED, or MYR only): USD
What currency do you want?: AED
How much you want to convert? : 100
Thank you. The converted amount is AED367.32. We will take AED10 commission, and you will get 357.32.
Please enter your currency (USD, AED, or MYR only) : AED
What currency do you want?: USD
How much you want to convert? : 367.32
Thank you. The converted amount is USD100. We will take AED10 commission, and you will get USD97.28.
import java.util.*;
class currency1
{
public float U_T_A = 3.6732F;
public float U_T_M = 4.22F;
public float total0;
public final float USD_TO_AED(float amount)
{
total0 = amount * U_T_A;
return total0;
}
public final float USD_TO_MYR(float amount)
{
total0 = amount * U_T_M;
return total0;
}
}
class currency2
{
public float A_T_U = 0.27F;
public float A_T_M = 1.14F;
public float total1;
public final float AED_TO_USD(float amount)
{
total1 = amount * A_T_U;
return total1;
}
public final float AED_TO_MYR(float amount)
{
total1 = amount * A_T_M;
return total1;
}
}
class currencytest
{
public float M_T_U = 0.87F;
public float M_T_A = 0.23F;
public float total2;
public final float MYR_TO_USD(float amount)
{
total2 = amount * M_T_U;
return total2;
}
public final float MYR_TO_AED(float amount)
{
total2 = amount * M_T_A;
return total2;
}
}
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
currency1 US = new
currency1();
currency2 AM = new
currency2();
currencytest MY = new
currencytest();
String a;
String b;
float c;
float d;
float e;
float f;
float g;
System.out.print("Please enter your
currency (USD,AED,MYR):");
a =input.next();;
System.out.print("What currency do
you want?:");
b =input.next();;
System.out.print("How much you want
to convert?:");
c = input.nextFloat();;
switch (a)
{
case
"USD":
if (c >= 8.10F)
{
if (b.equals("AED"))
{
d = US.USD_TO_AED(c);
if (d >= 900F)
{
f = 50F;
System.out.print("The
converted Amount is ");
System.out.print(b);
System.out.print(d);
System.out.print(".We will
take commission AED50,and you will get ");
System.out.print(b);
System.out.print(" ");
System.out.print(d -
f);
System.out.print("\n");
}
else
{
g = 10F;
System.out.print("The
converted Amount is ");
System.out.print(b);
System.out.print(d);
System.out.print(".We will
take commission AED10,and you will get ");
System.out.print(b);
System.out.print(" ");
System.out.print(d -
g);
System.out.print("\n");
}
}
else if (b.equals("MYR"))
{
d = US.USD_TO_MYR(c);
if (d >= 1026F)
{
f = 57F;
System.out.print("The
converted Amount is ");
System.out.print(b);
System.out.print(d);
System.out.print(".We will
take commission AED50,and you will get ");
System.out.print(b);
System.out.print(" ");
System.out.print(d -
f);
System.out.print("\n");
}
else
{
g = 11.4F;
System.out.print("The
converted Amount is ");
System.out.print(b);
System.out.print(d);
System.out.print(".We will
take commission AED10,and you will get ");
System.out.print(b);
System.out.print(" ");
System.out.print(d -
g);
System.out.print("\n");
}
}
}
else
{
System.out.print("You are not able to convert with this much
Amount");
System.out.print("\n");
}
break;
case
"AED":
if (c >= 30F)
{
if (b.equals("AED"))
{
d = US.USD_TO_AED(c);
if (d >= 244.98F)
{
f = 13.61F;
System.out.print("The
converted Amount is ");
System.out.print(b);
System.out.print(d);
System.out.print(".We will
take commission AED50,and you will get ");
System.out.print(b);
System.out.print(" ");
System.out.print(d -
f);
System.out.print("\n");
}
else
{
g = 2.722F;
System.out.print("The
converted Amount is ");
System.out.print(b);
System.out.print(d);
System.out.print(".We will
take commission AED10,and you will get ");
System.out.print(b);
System.out.print(" ");
System.out.print(d -
g);
System.out.print("\n");
}
}
else if (b.equals("MYR"))
{
d = US.USD_TO_MYR(c);
if (d >= 1026F)
{
f = 57F;
System.out.print("The
converted Amount is ");
System.out.print(b);
System.out.print(d);
System.out.print(".We will
take commission AED50,and you will get ");
System.out.print(b);
System.out.print(" ");
System.out.print(d -
f);
System.out.print("\n");
}
else
{
g = 11.4F;
System.out.print("The
converted Amount is ");
System.out.print(b);
System.out.print(d);
System.out.print(".We will
take commission AED10,and you will get ");
System.out.print(b);
System.out.print(" ");
System.out.print(d -
g);
System.out.print("\n");
}
}
}
else
{
System.out.print("You are not able to convert with this much
Amount");
System.out.print("\n");
}
break;
case
"MYR":
if (c >= 34.2F)
{
if (b.equals("AED"))
{
d = US.USD_TO_AED(c);
if (d >= 900F)
{
f = 50F;
System.out.print("The
converted Amount is ");
System.out.print(b);
System.out.print(d);
System.out.print(".We will
take commission AED50,and you will get ");
System.out.print(b);
System.out.print(" ");
System.out.print(d -
f);
System.out.print("\n");
}
else
{
g = 10F;
System.out.print("The
converted Amount is ");
System.out.print(b);
System.out.print(d);
System.out.print(".We will
take commission AED10,and you will get ");
System.out.print(b);
System.out.print(" ");
System.out.print(d -
g);
System.out.print("\n");
}
}
else if (b.equals("MYR"))
{
d = US.USD_TO_MYR(c);
if (d >= 244.98F)
{
f = 13.61F;
System.out.print("The
converted Amount is ");
System.out.print(b);
System.out.print(d);
System.out.print(".We will
take commission AED50,and you will get ");
System.out.print(b);
System.out.print(" ");
System.out.print(d -
f);
System.out.print("\n");
}
else
{
g = 2.722F;
System.out.print("The
converted Amount is ");
System.out.print(b);
System.out.print(d);
System.out.print(".We will
take commission AED10,and you will get ");
System.out.print(b);
System.out.print(" ");
System.out.print(d -
g);
System.out.print("\n");
}
}
}
else
{
System.out.print("You are not able to convert with this much
Amount");
System.out.print("\n");
}
break;
default:
System.out.print("Enter valid input");
System.out.print("\n");
break;
}
}
}
output: