CMPT166 Lab0: Template Lab Write-up
Display a running total of a sequence of integers entered by the user.
This is quite a trivial problem, well within the reach of a calculator (or
However, the solution does illustrate how the problem-solving
process works, from problem statement to design to implementation.
- Given: A sequence of integers entered by the user
- To Do: Calculate the sum of all integers entered thus far
- Desired Result: Running total
- Formula: (none applicable)
This program uses the basic Java libraries.
It is coded as a Java applet, and so uses the applet libraries.
Problem Refinement (natural language pseudocode):
- Input Section:
Second Refinement (natural language pseudocode):
- Define a text input widget and bind it to the applet
- When the user presses enter, retrieve the value from the input widget
and convert it to an integer
- Add the retrieved integer value to the running total
- Convert the integer running total to a string and set the status bar
text accordingly (could also use a label widget)
- Clear the text input widget
number (int): the integer value entered by the user
sum (int): the integer running total
input (TextField): text input widget for number
(it is not necessary to include all widgets here (e.g., prompt --
see code), just the ones used for
Addition is a trivial little applet that keeps a running total of integers
entered by the user.
There is just one text box in the applet window:
Type in an integer value and press Enter. It can be negative, but must not
contain any decimal points, commas, or other non-numeric characters (letters,
- Enter integer and press Enter:
Each time you type a number and press Enter, the status bar will be updated
to show the current running total. Keep entering numbers to see the status bar
Test Cases, with expected results:
Put some effort into designing your test cases; QA is a challenging job!
The idea is that if your program passes all the test cases, you'd be confident
shipping it to a paying customer.
Normal Test case:
- Enter integer and press Enter: 100
- Enter integer and press Enter: -165
- Enter integer and press Enter: 033
- Status bar: -32
Test case that breaks (invalid input):
- Enter integer and press Enter: -55
- Enter integer and press Enter: 2.5
- (Applet ignores input or crashes)
(Can be embedded here or left as separate files if you like,
but list the filenames here.)
This write-up is done in HTML as a webpage, and this sample lab is done as a
Java Applet. If you do this as well, you may opt to embed your applet
directly into your lab write-up. But you should still have static
screenshots in your write-up.