home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
hw-ec01-ClockDisplay
Program organization
hw-ec01
Due Mar.20 (Tue after spring break) 17:00;
15pts.
A general note on extra-credit homeworks:
-
They tend to be more work (point-for-point) than regular homeworks.
-
They are not always as spelled out for you:
sometimes you'll want/need to write a method or include a field
even though the assignment doesn't explicitly say so.
-
They should be fully polished: make sure the documentation
really is descriptive, check for good grammar and spelling, etc..
Don't include fields/methods you never use.
(All this applies to ordinary homeworks too, but
we'll cut less slack for extra-credit homeworks.)
ClockDisplay12: another approach
Modify ClockDisplay so that instead of keeping track
of time internally as hours-since-midnight,
it keeps track of time internally in a 12-hour format.
(Realize that the internal information kept by our class
is different from what methods and fields we have.)
This will make it easier for the ClockDisplay to give people
a string in 12-hour format,
but it will make it more difficult to update the time for each
timeTick.
-
To keep track of the hours, you'll have a class NumberCounter1.
A NumberCounter1 is similar to a NumberCounter except that
(a) instead of tracking a number in [0,limit) it tracks a number in [1,limit].
(b) When asked to getDisplayValue, it doesn't pad its answer out to 2 digits.
NumberCounter1 should have all the same methods
as NumberCounter.
-
Now, write a new class ClockDisplay12 so that it
still contains a NumberCounter (for the minutes [0,60)),
but to keep track the hours it uses a NumberCounter1 for the hours. in [1,12].
-
Since you only keep track of 12hrs, you'll need to keep track of
one additional bit of information: is the current time before-noon,
or is it noon-or-after?
What is a good Java data type, to represent this bit of state?
-
Other people will use a ClockDisplay12
just like they use ClockDisplay:
You'll still implement both getTime24
and getTime12.
-
Well, you will want to modify the number of
inputs to setTime,
to reflect the fact that people setting the clock will
now be thinking in terms of 12hrs, not 24hrs.
-
Ignore the book's second (“overloaded”) version
of the constructor which takes inputs;
your constructor should take no inputs and have the
time initially set to midnight.
Of course, you'll want to write stub functions and
test case for each of these two new classes.
The following is an example, but it is not anywhere near a
complete set of test cases.
ClockDisplay12 c = new ClockDisplay12();
c.getTime12() = "12:00am"
c.getTime24() = "00:00"
c.timeTick();
c.getTime12() = "12:01am"
c.getTime24() = "00:01"
c.setTime( 1, 23, ); // You get to decide how the user will specify am vs pm.
c.getTime12() = "1:23pm"
c.getTime24() = "13:23"
|
Observe how, with the exception of setTime,
these same cases could have been called with our original
ClockDisplay from hw05.
You may wish to look at the
hw05 solution, once posted.
You may build on top of your hw05-soln or the published version (or neither),
but be sure to indicate author (including yourself) and
credits (to the book and, possibly, the posted solution)
in the program's opening comments.
Also turn in a paragraph comparing
the two implementations (for hw05 and this assignment).
Which seems easier to write?
Is it easier to understand the organization of
one approach or the other?
By the way, I suspect that the approach required here is
what the book probably expected for 3.30,
and the approach on hw05 was what they hinted at in 3.31.
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs