Project 3: Composition & Aggregation

This project is designed to teach about composing and aggregating objects as a mechanism for organizing code well.

Goal: Write code to implement a Counter class, as described here. Then, using inheritance or composition, you will implement a GraphicCounter class and use it to display a countdown timer in a graphical window on the screen.

The Counter Class

Define a class called Counter. It is used to count things, so it records a number that is a non-negative whole number. Include methods to set the counter to given value, increment the value by 1, and decrement the value by 1. The value of the counter can be negative. Also include a method that returns the current value of the counter, and override the toString method to return a String representation of the current value.

You will be provided a test driver class called CounterTest.java, already written. You must write your Counter class to conform
to the API specified in this test class--you are NOT allowed to modify the test driver in any way!!! It will help you to look
at the Counter.html Javadoc provided below, to figure out what methods you need to implement. You will need generate Javadoc
for everything when you are done.

Look in the CounterInitializationException.java code file, and the test driver code, for information about
when this exception is thrown.

The GraphicCounter Class

Define a GraphicCounter class threat uses the Counter class either by inheritance or composition. You should display the GraphicCounter in a Window on the screen. Provide this class with any reasonable methods you need.

The Application

Use the GraphicCounter class in an application that behaves like a timer. Set the initial value in seconds, and watch as the timer counts down to 0. The graphical display should change as it counts.

Reminder: Remember that you must demonstrate running code to your instructor, who may suggest or require
changes, before your project will be graded. Allow yourself enough time to succeed.

Files

CounterTest.java

CounterInitializationException.java

Counter.html

Things to Think About


Note: You don't have to hand these things in. They will help you do a good job, though.
  1. What responsibilities does the Counter class have?
  2. What values does the Counter class need to implement these responsibilities?
  3. Are there any constraints on these values?
  4. Make a list of constructors and methods that will be used to implement the Counter class.
  5. Make a list of test cases used to test the Counter class.
  6. Answer 1 - 5 for the GraphicCounter class.