CS 161 Lab I - Coin Collection

Due Thurs Apr 11 at 11:59pm

Overview

In this lab, you will be writing a simple program to organize, analyze, and display a collection of exotic and interesting coins. You will use a different class for each type of coin, taking advantage of inheritance and polymorphism to easily implement your program.

This lab will be completed in pairs. Be sure to review the pair programming guidelines. You also must work with a different partner than you have before!

Objectives

Necessary Files

You will need to download and extract the BlueJ project from the LabI.zip file. This project will supply you with the following classes:

The project also includes an images folder that contains some of the images you will use to display the coins.

Details

In this lab, you will be making a significant number of new classes. These are described below

BEFORE YOU BEGIN: skim through all of the instructions, to get a sense for what you will need to do and what classes you will need. Hint: the first thing you should make is described last!

Other coin classes

The main thing you will need to do is to create classes to represent specific types of coins. Each of these classes should extend the provided Coin class.

CoinInspector

You will also need to create a new class called CoinInspector. This class will contain a number of static methods that will each analyze a given ArrayList of Coins (provided as a parameter):

  1. totalValue() This method should calculate the total value of the Coins in the ArrayList, and return that value. This should be straightforward.
  2. mostValuable() This method find and return the "most valuable" Coin in the ArrayList (that is, the coin with the highest value). You can use a basic king-of-the-hill search for this. Note that the values of the coins are doubles, and so can be compared using the normal < and > operators.
  3. mostCommon() This method should return the name of the "most common" type of coin in the ArrayList. To figure this out, you will need to go through the list and count the number of times each coin type appears in the list. Then go through those counts to determine which is the most common.
    • This is a great place to use a HashMap! Make a map linking the name of a coin type to the number of coins. Then for every coin you can get the current count, increase it by one, and then put that increased count back in the HashMap. (Hint: remember to check that the coin type already has an entry in the map--if not, you will need to create a new one!)
    • Once you have all the counts in the HashMap, you can iterate through the keys in the HashMap and do another king-of-the-hill search for which count is the largest. Remember that you can iterate through the keys using for(Type key : list.keySet()) (be sure and replace Type and list with appropriate values.)

CoinTester

Finally, you will also need a Tester class to run and test your code. In this tester, you should make a new ArrayList of Coins, add lots of different coins (of all types), and then call the three static methods. You should also use the CoinDisplay to show your coins!

Make this class first! Then you can use it to test all of your other code.

Submitting

Grading

This assignment will be graded on approximately the following criteria: