• Java 2 Platform Standard Edition 5.0 API specification
• OpenJDK source code repository for library classes
• Source code from Data structures and problem-solving using Java, third edition
Often, at a large public event, some hireling of the promoter will stand at
the entrance and count the number of attendees by repeatedly clicking a
button on a small hand-held mechanism: a tallier. This
mechanism has only three functions: a reset that sets its internal
counter to 0, a tally that adds 1 to the internal counter when the
button is clicked, and a report function that recovers the value of
the internal counter, i.e., the number of tally operations performed
since the last reset operation.
tallying for the
classes we develop in this lab.Tallier class that supports
these three functions, implementing each as a non-static method. How many
fields, if any, will a Tallier need?main method that creates two talliers and sends them
messages demonstrating that they can count independently of one another.The designers at UPCorp (formerly Useless Products, Inc.) have designed a new kind of tallier with an additional function: When it is touched back-to-back to any other UPCorp tallier, the contents of the internal counter of the other tallier are automatically added to its own internal counter. (For example, if one of these "deluxe talliers" reads 389, and it is touched to another tallier that reads 114, the deluxe tallier's internal counter will change to 503.)
DeluxeTallier class that extends Tallier and
models this additional function in the form of a new collect method
that takes the other tallier as an argument.DeluxeTallier is touched
back-to-back to another DeluxeTallier?collect
method to ensure that this happens in your model whenever the argument to
collect is a DeluxeTallier. You may find that you need to
provide an additional method to make this work.main method for the DeluxeTallier class that
checks to make sure that the collect works as it is supposed to,
both with non-deluxe talliers and with deluxe ones.
For the new model year, the designers at UPCorp want to develop talliers
that can not only report their internal counter readings as int
values, but can convert the reading to a String and display it on a
small LCD screen on the front of the tallier. All DeluxeTalliers
will provide this function in some form, but the particular string that is
displayed will be different in different markets: The USDeluxeTallier will use standard decimal numeration and Arabic numerals,
the ChinaDeluxeTallier will use Han ideographs, and the AldebaranDeluxeTallier, for the UFO-pilot market, will use base-eight
numeration (with Arabic numerals).
DeluxeTallier to an abstract class with an abstract
show method that takes no arguments and returns a String.USDeluxeTallier and AldebaranDeluxeTallier classes as extensions of DeluxeTallier, each
providing its own overriding show method.Showable interface, containing just the abstract show method? What would be the advantages and disadvantages of such an
approach?