Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project Description When traveling abroad, it is a good idea to secure some of the local currency before you arrive. This project will quote currency

Project Description

When traveling abroad, it is a good idea to secure some of the local currency before you arrive. This project will quote currency exchange rates from different banks.

The Bank Information

Each bank can exchange three currencies to and from US dollars. For each currency, there is a rate at which the bank will buy and sell the currency in exchange for US dollars. In addition, the bank charges a commission as a fee for performing the exchange. All of this information is specified a file for each bank, which will be in the following format

bank name commission_rate currency_code exchange_rate currency_code exchange_rate currency_code exchange_rate

An example file follows:

Shady Airport Bank

0.2 GBP 0.64

CAD 1.24

JPY 119.2

This file says that the Shady Airport Bank charges a commission of 20%. They will buy one Great Britain Pound for 0.64

US dollars and will sell you one Great Britain Pound for 0.64 US dollars. The last two lines give the exchange rates for Canadian dollars and Japanese Yen. Note that other files might have different currency codes, but the codes do not contain any spaces, and each file will have exactly three codes. When your program starts, it should read the bank information from two bank files, "bank1.txt" and "bank2.txt". The information about each bank will be stored in a Bank object, as detailed in the Design section.

Exchange Quotes

After reading the bank information, your program should prompt the user to enter

the type of transaction ("buy" or "sell")

the currency code (e.g., "GBP" or "gbp" or "Gbp")

the amount of the foreign currency to buy or sell

Then the program will display quotes from the two banks for the proposed currency exchange. All of this input and output happens at the console, with the exception of one JOptionPane to ask if the user wants to conduct another transaction. Here is an example, which defines the messages you should print (output is in normal font, input is bold font):

Do you wish to buy or sell? what Please try again.

Do you wish to buy or sell? buy

Which currency? Schrutebucks

I'm sorry. There is no bank that can exchange SCHRUTEBUCKS. Please start again.

Do you wish to buy or sell? sell

Which currency? jpy

There is one bank that can exchange JPY.

How many JPY? 4858.28

Big Name Bank will give you 342.48 USD for 4858.28 JPY, after collecting a commission of 33.87 USD (9%)

[JOptionPane asks if you want to get another quote, and you say Yes]

Do you wish to buy or sell? buy

Which currency? Cad

There are two banks that can exchange CAD.

How many CAD? 1000

Big Name Bank will give you 1000.00 CAD for 742.34 USD, after collecting a commission of 66.81 USD (9%)

Shady Airport Bank will give you 1000.00 CAD for 843.91 USD, after collecting a

commission of 168.78 USD (20%)

[JOptionPane asks if you want to get another quote, and you say No]

Notice that all currency amounts are rounded to two digits after the decimal point, and the commission percentage is rounded to the nearest whole percent. Also, note that when the program displays output about the currency, the code is in UPPER CASE, the same way it will be in the file. However, the program should accept input from the user in any case (and convert it to upper case internally).

Analysis and Design

As you gain experience with programming, you will be able to analyze the description above and create a program to compute the desired information. However, since this is an introductory course, we will guide you through the analysis part and help you design your program.

This is the first project for which you will be writing your own classes. The classes should follow the design described hereafter. Do not add, change, or remove methods or data members from that design. The number of points for each part is listed below (subject to change).

Currency Class (10 points)

Each currency line in one of the bank information files will be translated into an instance of a Currency class that should contain the following:

[2 pts] Two private data fields, one to hold the currency code and one to hold the exchange rate. Note that the exchange rate for the same currency could be different for different banks.

[4 pts] A constructor that takes two arguments: the currency code and exchange rate. The constructor should assign the private members from the values of the arguments.

[4 pts] An accessor method for each data field.

Bank Class (34 points)

Each bank will be represented by an instance of a Bank class, which should contain the following:

[5 pts] Five private data fields o The name of the bank o The commission rate o Three fields for the three currencies exchanged by the bank. Each of these should have type Currency.

A constructor that takes a file name (a String) as an argument. The constructor should... o [2 pts] open the file, o [8 pts] read in the information about the bank, initializing all of the bank's data fields.

[3 pts] A method supportCurrency that takes a currency code (a String) as its only argument. It should return true if the bank can exchange the given currency and false if it cannot.

[4 pts] A method getRate that takes a currency code (a String) as its only argument. It should return the rate of exchange for that currency, or -1.0 if the bank does not exchange that currency.

Two additional methods: quoteBuy and quoteSell. Each of these takes two arguments, a double for the amount of foreign currency, and a String for the currency code. Each method will return a Quote object (defined below) if the bank supports that currency and null if the bank does not. Within your quote methods, you should call the getRate method you wrote earlier.

Use the following formulas to calculate the number of US dollars and the bank's commission: o For selling amt units of currency with exchange rate rate, the number of US dollars before commission is amt / rate; call that base. Then the commission is the commission rate times base. The amount of US dollars the customer will receive is base minus the commission.

o For buying amt units of currency with exchange rate rate and commission rate com (where com is between 0.0 and 1.0), the number of US dollars the customer will pay is amt / (rate * (1

- com)); call that dollarsOwed. The commission is com * dollarsOwed.

[For each of buy and sell, the method prototype is worth 1 point, the correct calculation is worth 3 points, and creating and returning a Quote object is worth 2 points.]

Quote Class (16 points)

You will define a Quote class to capture the information about a potential currency exchange. It should contain the following:

[3 pts] Seven private data fields: o The name of the bank issuing the quote o The currency code of the currency given to the bank. Call this codeToBank. o The currency amount given to the bank. Call this amtToBank.

The currency code of the currency received from the bank. Call this codeFromBank. o The currency amount received from the bank. Call this amtFromBank. o The commission rate charged by the bank. o The dollar amount of the commission.

A DecimalFormat object for formatting currencies (i.e., two digits after the decimal point).

[3 pts] A constructor that takes 7 arguments, corresponding to the first 7 data fields listed above. The constructor should set those fields from the values of the arguments. It should also create an object and assign it to the DecimalFormat field.

[10 pts] A method called toString that takes no arguments and returns a String. It should return the message that will be printed out for the quote, as listed above (i.e., "Shady Airport Bank will give

you 1000.00 CAD for 843.91 USD, after collecting a commission of 168.78 USD

(20%)"). Note that the commission amount should always be reported in US dollars.

CurrencyExchange Class (25 points)

Your main method should be in a CurrencyExchange class. It should follow this control flow: [2 pts] Create two Bank objects, one for each file "bank1.txt" and "bank2.txt"

do{ o [1 pt] Prompt the user if they want to buy or sell and get the user input o [2 pts] If the input is not valid, print error message and use continue to restart the loop o [1 pt] Prompt the user for the foreign currency and get the user input [3 pts] Check how many banks support that currency

[1 pt] If none, print the error message and use continue to restart the loop

[1 pt] Otherwise, print how many banks can exchange that currency o [1 pt] Prompt the user for the amount of foreign currency and get the user input

[3 pts] Use the quoteBuy or quoteSell methods of the Bank objects to get a Quote from every bank supporting the foreign currency.

[4 pts] Print the quote(s) from the bank(s), using the toString method of the Quote object(s).

[4 pts] Use a JOptionPane with Yes and No options to prompt the user if they want to perform another transaction.

[2 pts] while the user wants to continue performing transactions

Commenting and Style (15 points)

[4 pts] Comments should be clearly written with correct grammar and spelling.

[4 pts] Indentation and general appearance should be consistent and make the code easy to read.

[4 pts] You should write a comment for each major piece of computation. For example, // Compute the commission

[3 pts] You should also write a comment at the top of each class file with the following content:

/*

CS16000 Spring 2015

Project 3: Currency Exchange

*

Description: */

Testing

I recommend testing your program on a variety of cases. You can use the example bank file in the first section of these instructions as a starting point. Make sure that you test that your program correctly handles incorrect user input for the buy/sell question and the currency question. You can assume that the currency amount that the user enters is a valid, positive floating point number.

Here is a hint for checking your formulas: If you buy some amount of foreign currency for X US dollars and then sell that same amount back to the same bank, you should receive X minus the sum of the two commissions (for buying and selling). It is okay if they are not strictly equal but are off by a cent or two due to rounding.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions

Question

Find the derivative of y= cos cos (x + 2x)

Answered: 1 week ago

Question

2. What are the different types of networks?

Answered: 1 week ago