CASE STUDY
402
TOTALING RAINFALL AMOUNTS
Problem:You are working for a scientific research project that is keeping track of the to-
tal rainfall in your area. Observers from different stations call you to report how much
rain has fallen at the end of a storm. You need to enter the values for each station as
they come in and display the running total for each station.
Brainstorming:We begin by looking at the nouns in the problem statement as the start
of our brainstorming. They are you,project,total rainfall,observers,stations,storm, and val-
ues. Going back over the list, you realize that projectand stormare not really objects;
they just give information about the context of the problem. Here is your first pass at
the classes in the problem:
Filtering:Values and total rainfall are numeric values, so we don’t need classes for
them. What are observers? They are the people who provide the rainfall values, so they
are not a class in our problem solution. However, this reminds us that we must have a
frame to input the rainfall values. What does “you” represent? The processing that must
be done. As you cannot actually do the processing within the machine, you are respon-
sible for seeing that the values are input and the total is calculated and displayed. That
is, you are responsible for developing the algorithmic solution and writing the code to
carry out the tasks. Stations are the different places from which you receive values and
for which you need to keep totals. They sound like actual objects, so let’s make a Station
class, and then we can instantiate an object for each station. Here is our filtered list:
Stations
User interface frame
You
Total rainfall
Observers
Stations
Values