This assignment has four objectives. You will:
- Learn about software design reuse by studying a
provided framework for problem solving
that has abstracted the general features of the bridge crossing program
from the previous assignment.
- Adapt your bridge crossing program to work with the framework.
- Apply the framework to allow users to solve a new problem, the
"Water Jug" problem.
- Write your own test classes for unit testing of the water jug
problem program.
Upon completion, this assignment will have two working programs:
- A revision of the previous program that allows its user to solve
the bridge crossing problem in exactly the same was as before
- A new program that allows its user to solve the water jug problem
Applets showing the behavior of these programs follow.
(Note: to restart the applet below, simply reload this page and select
Bridge from the menu on the left.)
(Note: to restart the applet below, simply reload this page and select
Water Jug from the menu on the left.)
Frameworks consist of generally useful code that can be used with more
than one application.
This section briefly describes the motivation behind frameworks, the
elements typically contained in frameworks, and how frameworks
contribute to code reuse.
Frameworks often arise from the realization that separate program
applications have similar structure.
For example, in both the bridge crossing and water jug problems,
- There is a fixed number of problem states.
- There is a fixed number of well-defined possible moves.
- The problem is to transform the current state into a goal
Examining two separate implementations of these problems would reveal
repeated code.
A framework manages repeated code so that it can be shared among
multiple applications.
The problem solving framework you will use consists of an
interface,
two
abstract classes,
and a
concrete class.
- The concept of an interface type in Java is not taken
up in our text book until chapter 4 (relevant pages: 137—144),
but it is like a C++ class with:
- No state
- Only pure virtual methods (ones with no implementation)
- An interface is intended to be implemented.
- The concept of an abstract class in Java is not taken
up in our text book until chapter 6 (relevant pages: 215—222), but
it is like a C++ class that has at least one pure virtual method.
- An abstract class is intended to
be extended (subclassed).
- A concrete class is not abstract. All classes in the previous
assignment were concrete.
- We will present a general framework of code that is "abstracted"
out of your bridge crossing problem solution in such a way that the framework
code does not depend on specific classes like BridgeState,
BridgeMove, etc.
- The advantage of this is that the framework code
can be applied to the water jug problem.
- Since frameworks are meant to be reused, they must never be altered
by application programmers.
- Reimplementing the bridge crossing problem does not require
new code, since the framework is designed to use code that's already
written.
- Adapting code to a
more general design in this way is called refactoring the
design.
- Study the provided framework classes to understand their function
- Refactor your bridge crossing code to work with the framework
- Develop classes to implement the water jug problem
- Develop classes to test the water jug implementation classes
The implementation and test classes have been started for you.
The source code for the implementation packages is described in this
section.
- The NetBeans project for you to use is here:
CS_2511_Framework.zip.
- The project folder is CS_2511_Framework.
- Java documentation for the package APIs can be viewed here
(will generate a new tab):
Javadoc.
This section describes the tests to be used in unit testing for this assignment.
- The bridge crossing test classes are provided for you.
- They are the same as or essentially the same as those for the
first assignment.
- As in the first assignment, test the overall program by running
the BridgeConsole class.
- The water jug test classes are started for you but you must complete
them.
- Use the corresponding bridge crossing test classes as models.
- Test the overall program by running
the WaterJugConsole class.
When your program is working correctly you will submit your entire Netbeans
project, but first:
- To double-check that everything is in order, click Build on
the menu bar and select Clean and Build Main Project.
- Run the three bridge test classes and the BridgeConsole class
to make sure everything works.
- Run the three waterjug test classes and the WaterJugConsole class
to make sure everything works.
Outside of NetBeans, zip your project folder as
your-login-PA2.zip.
Email the zip file to your TA.
- Bridge crossing code refactoring: 5 points
- Water jug code implementation class correctness: 15 points
- Water jug unit testing class completeness: 10 points