Money

Design, implement, and test a reusable Money class.

Are money objects values or references?

You should be able to represent at least five different currencies:

USD, EUR, INR (Indian Rupees), MXP (Mexican Pesos), JPY (Japanese Yen)

Include operations for adding money amounts.

Implement Java’s Comparable interface. The compareTo method is called by List.sort.

Implement Java’s Serializable interface. This allows Money objects to be saved to and read from files.

We should be able to add and compare money objects even if they are different currencies. To do this, create a currency converter interface with a mock implementation.

CurrencyConverter.java

Provide an interface to a currency conversion service. How could this interface be implemented?

To be useful, Money objects should also be serializable so they can be saved to and read from files.

Turn in:

1.     A class diagram showing all classes and interfaces to be implemented (together with fields and operations).

2.     Implementation of all classes and interfaces from the diagram.

Here is a test harness for your implementation:

TestMoney.java

Here’s the output I get:

deposits = [3.25 USD, 5.0 EUR, 129.0 MXP, 200.0 INR, 100.0 JPY]

deposits = [100.0 JPY, 200.0 INR, 3.25 USD, 5.0 EUR, 129.0 MXP]

m2 + m3 = 11.45 EUR

m2 + m4 = 7.592592592592593 EUR

m2 + m5 = 5.842592592592593 EUR

m2 + m1 = 8.00925925925926 EUR

My test harness uses a mock converter that uses exchange rates from Feb 18, 2020.