Question

In: Computer Science

Using the object-oriented programming principles, write a currency exchange converter in Java. You should also use...

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.

Solutions

Expert Solution

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:


Related Solutions

This program should be done in python. This must use the principles of object oriented program....
This program should be done in python. This must use the principles of object oriented program. Create one or more classes to play Four-in-a-Row (also called Connect Four) with a user. It’s similar to tic-tac-toe but the board is of size 7×6 and discs fall straight through so the legal moves are more stringent than tic-tac-toe. The state of the board should be printed to the terminal after each legal move. You can represent the different colored discs as X’s...
Write a C++ program that will use good object-oriented principles. You have been tasked to write...
Write a C++ program that will use good object-oriented principles. You have been tasked to write an application that will allow a user to change their system password. The XYZ Corporation has the following rules for passwords: each password should have a minimum of 8 characters each password should have a minimum of 2 uppercase characters (A - Z) each password should have a minimum of 2 lowercase characters (a - z) each password should have a minimum of 2...
Why is it more feasible to use Objects and object oriented programming as compared to using...
Why is it more feasible to use Objects and object oriented programming as compared to using method based programs? What are the disadvantages of using only methods in your programs.
*OBJECT ORIENTED PROGRAMMING* JAVA PROGRAMMING GOAL: will be able to throw and catch exceptions and create...
*OBJECT ORIENTED PROGRAMMING* JAVA PROGRAMMING GOAL: will be able to throw and catch exceptions and create multi-threaded programs. Part I Create a class called Animal that implements the Runnable interface. In the main method create 2 instances of the Animal class, one called rabbit and one called turtle. Make them "user" threads, as opposed to daemon threads. Some detail about the Animal class. It has instance variables, name, position, speed, and restMax. It has a static boolean winner. It starts...
In this assignment, you will practice solving a problem using object-oriented programming and specifically, you will...
In this assignment, you will practice solving a problem using object-oriented programming and specifically, you will use the concept of object aggregation (i.e., has-a relationship between objects). You will implement a Java application, called MovieApplication that could be used in the movie industry. You are asked to implement three classes: Movie, Distributor, and MovieDriver. Each of these classes is described below. The Movie class represents a movie and has the following attributes: name (of type String), directorsName (of type String),...
i need a full explanation in details Object Oriented Programming Principles Principles Polymorphism Inheritence Encapsulation Abstraction...
i need a full explanation in details Object Oriented Programming Principles Principles Polymorphism Inheritence Encapsulation Abstraction Class Object Method Message Passing
*OBJECT ORIENTED PROGRAMMING* *JAVA PROGRAMMING* Create a program that simulates a race between several vehicles. Details...
*OBJECT ORIENTED PROGRAMMING* *JAVA PROGRAMMING* Create a program that simulates a race between several vehicles. Details don't matter code must just have the following: Design and implement an inheritance hierarchy that includes Vehicle as an abstract superclass and several subclasses. Include a document containing a UML diagram describing your inheritance hierarchy. Include at least one interface that contains at least one method that implementing classes must implement. Include functionality to write the results of the race to a file; this...
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester. The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester.    The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester. The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT