Requirement: In this assignment, you are going to handle exceptional cases in the bank account class for foreign currencies. In the attached files, source codes for ForeignCurrencyAccount and Account classes are given. There is also Test3.java and Transaction.java that run operations on the bank accounts. Please complete the implementation of ForeignCurrencyAccount and Account classes, so that following exceptional cases are handled by them. Do not add new attributes or methods to ForeignCurrencyAccount and Account classes. Just add code to throw exceptions or handle exceptions. Exceptional cases: 1. Whenever a transaction amount given to "withdraw" method is greater than account's balance, an exception of class InsufficientFundsException should be thrown. 2. Whenever InsufficientFundsException is caught within buyForeignCurrency or sellForeignCurrency methods, an Exception should be thrown with description "Foreign currency buy/sell transaction failed because of insufficient funds". 3. Whenever setCurrencyCode method is called with a different currency code than the account's currency code and account has non-zero balance, an Exception should be thrown with description "Currency code cannot be changed for an account that has balance". 4. Whenever dailyExchangeRate is zero and a method that uses dailyExchangeRate (for example, convertToCAD method) is called, an Exception should be thrown with description "Daily exchange rate not set". Expected output: Account: 1122 my checking account Balance: 3200.0 CAD Account: 3984 my USD account Balance: 4000.0 USD Account: 4597 my EUR account Balance: 12000.0 EUR Account: 5921 my Australian Dollar account Balance: 1000.0 AUD assignment4.InsufficientFundsException at assignment4.Account.withdraw(Account.java:51) at assignment4.Test3.main(Test3.java:46) java.lang.Exception: Currency code cannot be changed for an account that has balance. at assignment4.ForeignCurrencyAccount.setCurrencyCode(ForeignCurrencyAccount.java:33) at assignment4.Test3.main(Test3.java:58) java.lang.Exception: Daily exchange rate not set. at assignment4.ForeignCurrencyAccount.convertToCAD(ForeignCurrencyAccount.java:25) at assignment4.ForeignCurrencyAccount.getBalanceInCAD(ForeignCurrencyAccount.java:44) at assignment4.Test3.main(Test3.java:66) Sum of all my accounts on day 1: 26360.0 CAD Changing exchange rates for day 2 java.lang.Exception: Daily exchange rate not set. at assignment4.ForeignCurrencyAccount.convertToCAD(ForeignCurrencyAccount.java:25) at assignment4.ForeignCurrencyAccount.getBalanceInCAD(ForeignCurrencyAccount.java:44) at assignment4.Test3.main(Test3.java:84) Sum of all my accounts on day 2: 25480.0 CAD Buying 100 USD Selling 50 EUR Buying 100000 JPY java.lang.Exception: Foreign currency buy transaction failed because of insufficient funds at assignment4.Transaction.buyForeignCurrency(Transaction.java:20) at assignment4.Test3.main(Test3.java:108) Account: 1122 my checking account Balance: 3140.0 CAD Account: 3984 my USD account Balance: 4100.0 USD Account: 4597 my EUR account Balance: 11950.0 EUR java.lang.Exception: Daily exchange rate not set. at assignment4.ForeignCurrencyAccount.convertToCAD(ForeignCurrencyAccount.java:25) at assignment4.ForeignCurrencyAccount.getBalanceInCAD(ForeignCurrencyAccount.java:44) at assignment4.Test3.main(Test3.java:116) Account: 5921 my Australian Dollar account Balance: 1000.0 AUD Account: 6568 my Japanese Yen account Balance: 0.0 JPY Sum of all my accounts after buying / selling foreign currency: 25480.0 CAD Deliverables: After completing your program, test it with the given Test2.java and make sure that your program generates the same output that is shown below. Please also test it by sending various inputs to make sure that your ForeignCurrencyAccount class is working perfectly.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Requirement:

In this assignment, you are going to handle exceptional cases in the bank account class for foreign currencies.

In the attached files, source codes for ForeignCurrencyAccount and Account classes are given. There is also Test3.java and Transaction.java that run operations on the bank accounts.

Please complete the implementation of ForeignCurrencyAccount and Account classes, so that following exceptional cases are handled by them.

Do not add new attributes or methods to ForeignCurrencyAccount and Account classes. Just add code to throw exceptions or handle exceptions.

Exceptional cases:

1. Whenever a transaction amount given to "withdraw" method is greater than account's balance, an exception of class InsufficientFundsException should be thrown.

2. Whenever InsufficientFundsException is caught within buyForeignCurrency or sellForeignCurrency methods, an Exception should be thrown with description "Foreign currency buy/sell transaction failed because of insufficient funds".

3. Whenever setCurrencyCode method is called with a different currency code than the account's currency code and account has non-zero balance, an Exception should be thrown with description "Currency code cannot be changed for an account that has balance".

4. Whenever dailyExchangeRate is zero and a method that uses dailyExchangeRate (for example, convertToCAD method) is called, an Exception should be thrown with description "Daily exchange rate not set".

Expected output:

Account: 1122 my checking account Balance: 3200.0 CAD Account: 3984 my USD account Balance: 4000.0 USD Account: 4597 my EUR account Balance: 12000.0 EUR Account: 5921 my Australian Dollar account Balance: 1000.0 AUD assignment4.InsufficientFundsException at assignment4.Account.withdraw(Account.java:51) at assignment4.Test3.main(Test3.java:46) java.lang.Exception: Currency code cannot be changed for an account that has balance. at assignment4.ForeignCurrencyAccount.setCurrencyCode(ForeignCurrencyAccount.java:33) at assignment4.Test3.main(Test3.java:58) java.lang.Exception: Daily exchange rate not set. at assignment4.ForeignCurrencyAccount.convertToCAD(ForeignCurrencyAccount.java:25) at assignment4.ForeignCurrencyAccount.getBalanceInCAD(ForeignCurrencyAccount.java:44) at assignment4.Test3.main(Test3.java:66) Sum of all my accounts on day 1: 26360.0 CAD Changing exchange rates for day 2 java.lang.Exception: Daily exchange rate not set. at assignment4.ForeignCurrencyAccount.convertToCAD(ForeignCurrencyAccount.java:25) at assignment4.ForeignCurrencyAccount.getBalanceInCAD(ForeignCurrencyAccount.java:44) at assignment4.Test3.main(Test3.java:84) Sum of all my accounts on day 2: 25480.0 CAD Buying 100 USD Selling 50 EUR Buying 100000 JPY java.lang.Exception: Foreign currency buy transaction failed because of insufficient funds at assignment4.Transaction.buyForeignCurrency(Transaction.java:20) at assignment4.Test3.main(Test3.java:108) Account: 1122 my checking account Balance: 3140.0 CAD Account: 3984 my USD account Balance: 4100.0 USD Account: 4597 my EUR account Balance: 11950.0 EUR java.lang.Exception: Daily exchange rate not set. at assignment4.ForeignCurrencyAccount.convertToCAD(ForeignCurrencyAccount.java:25) at assignment4.ForeignCurrencyAccount.getBalanceInCAD(ForeignCurrencyAccount.java:44) at assignment4.Test3.main(Test3.java:116) Account: 5921 my Australian Dollar account Balance: 1000.0 AUD Account: 6568 my Japanese Yen account Balance: 0.0 JPY Sum of all my accounts after buying / selling foreign currency: 25480.0 CAD

Deliverables:

After completing your program, test it with the given Test2.java and make sure that your program generates the same output that is shown below. Please also test it by sending various inputs to make sure that your ForeignCurrencyAccount class is working perfectly.

 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education