SDSU CS 535 Object-Oriented Programming & Design
Fall Semester, 2000
Assignment 1
    Assignment Index        
© 2000, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 13-Sep-00


Assignment 1
Money
Due 23 Oct

Background: Today most currencies are decimalized. For example in the United States the currency is a dollar, which is divided into 100 parts or pennies. This was not always the case. England once had pounds, shillings, pence, and farthings, where 4 farthings = 1 penny, 12 pence (plural of penny) = 1 shilling and 20 shillings = 1 pound. All items were priced in integral values of pounds, shillings, pence and farthings. One could not have 1.01 pounds. Similarly in Germany 400 pfennigs once made one mark. In early Belgium, its pound was divided into 20 schellingen and a schellingen was divided into 12 grooten.

These non-decimal units make it harder to make change and convert between currency. For example how many British pounds would the bank give you for 1,920 farthings? In this assignment you will write class(es) to handle the four currencies mentioned above.

In order to make it easy to reference a currency we will use the two-letter country codes in the following table.

Belgium
BE
Germany
DE
England
UK
United States
US

We will use the two-letter country code plus the first letter of the monetary unit. So 23 UKS is 23 British shillings, 12 DEM refers to 12 Germany marks.

We will start using the following currency exchange rates:

Exchange Rate 1900
Currency
Value in US Dollars
Belgium Pound (BEP)
0.193
German Mark (DEM)
0.238
English Pound (UKP)
4.866
US Dollar (USD)
1.00

So for example one Belgium pound was worth 19.3 cents in US currency in 1900.

In this assignment you are to produce class(es) that can be used to manipulate currency. These classes will be used later in software to handle personal finance and small business accounts. The software will allow people to write checks in different currency and a business to handle accounts in different currency. For the time being we will just support the four currencies listed above. However, the list will grow. The exchange rate does change.

Operations on currency that must be supported.

ASCII Representation . Must be able to convert between an ASCII representation of an amount of money and how the money is represented in the program

Reduction. Given an amount like 1008 UKF reduce it to 1 UKP and 1 UKS. Given that there are 4 farthings in a penny, an amount of money in reduced form should not have more than 3 farthings in it.

Conversion. Given an amount in one currency convert it to another currency. There are two important issues here. First, the exchange rates to change. Second when converting to a currency the amount must be valid in that currency. For example, in the United States we do not support fractions of a penny. So in converting 1 BEP to USD we could get either 19 or 20 cents, not 19.3 cents. In your program round the amount down to the nearest valid amount. So in this case you would get 19 cents.

Adding/Subtracting. Given two amounts of money in possible different currency we need to be able to add or subtract them. For example if a = 1.2USD and b = 231 BES your code should be able to compute a + b and a - b. The result should be in the currency of the left-hand operand (a in our example). In Java you can not use the symbols '+' and '-'.

Multiplying/Dividing. Given an amount of money we need to be able to multiple or divide it by a number. For example 2.5 USD * 2 is 5 USD.

You are to turn in your source code with unit tests.


References:
World Almanac and Encyclopedia, 1901, The Press Publication Co.

The History of Currency 1252 to 1894, Shaw, 1896, Burt Franklin.
    visitors since 13-Sep-00