Second Exercise using inheritance
For this exercise, you may choose ONE of the following (1 or 2):
- For the Bank program, introduce a subclass of Account called Savings, which has an instance variable interestRate of type double, an addInterest method which updates the balance by adding the interest, and reuses all other methods of Account. Test using JUnit.
== OR ==
- For the Explore (Game) program:
- Download Explore2013v2.jar. After saving the JAR file, right-click on it and use a decompression program such as 7-zip to extract the files to a directory, then open the directory as a project in BlueJ.
- To run the game, execute the main method of Driver.
- Add a new type of Valuable to the island by defining a new class (e.g. GoldCoin) that extends Valuable.
- Put one or more objects of this type on the island (update initializeCells method of Island) and print them (update toString method of Island).
- If you want the Explorer to be able to obtain these new valuable items, update the Explorer class as follows:
- Declare a new attribute to keep track of what the Explorer has, e.g. numberOfGoldCoins.
- Initialize the new attribute in the constructor.
- Update the move method so that after the destination location is computed (i.e. where the Explorer wants to move), get the cell at the destination location (via getCell method of Island), get the Entity in this cell (via the getEntity method of Cell), and check whether this Entity is an instanceof your new type/class; if so, update the new attribute appropriately (e.g. increment numberOfGoldCoins) and remove the valuable item from the cell (via the delete method of Cell).
- Run the program, play the game and determine if the new code works.