You are on page 1of 2

SW Architecture and Patterns Fall 2011

Assignment #3. Applying State Pattern for Treadmill


(Due: Nov. 15, 2011, In Class) 1. Overview of Treadmill Machine Treadmill machine is an exercise device which is used for walking or running. It has a control panel which is used by users to change various settings such as moving the pad, moving faster and stop moving the pad.

We wish to develop control software for treadmill machines. Assume that the hardware devices such as motor and LED displays have API for control software. 2. Requirements The machine has the following control panel for acquiring users input and displaying the time elapsed and the running distance in kilometers.
Start Pause
Stop Time

Distance (km)

1:30

8.51

Speed

Power button

When the button is pressed, the machine is turned on. The button runs in a toggle mode. That is, another pressing on the button turns off the machine.

Start button

When the Start button is pressed, the machine begins moving the running pad.

Pause button

When the Pause button is pressed, the machine stops moving the running pad, and waits for the next input. The Time and Distance information is persevered.

Soongsil University

-1-

2011 Soo Dong Kim

SW Architecture and Patterns Fall 2011

Stop button

When the Stop button is pressed, the machine stops moving the running pad, and deletes the Time and Distance information. It returns to the initial mode.

Faster button

When the Faster button is pressed, the machine increases the speed of the running pad by the pre-defined increment. A single click on the button increases 0.1 kilometers for the speed. When the button is pressed and kept hold, then the speed is continuously increased during the time period. For example, pressing and holding the button for 5 seconds will increase (0.1 x 5) kilometers for the speed.

Slower button

When the Slower button is pressed, the machine decreases the speed of the running pad by the pre-defined increment. A single click on the button decreases 0.1 kilometers for the speed. When the button is pressed and kept, then the speed is continuously decreased during the time period. For example, pressing and holding the button for 5 seconds will decrease (0.1 x 5) kilometers for the speed.

Safety Lock

When the Safety Lock is unplugged, the machine performs the same behavior as Stop button. Overview of Treadmill Machine

3. Draw a state transition diagram for the treadmill software.

4. Based on the state pattern and your state transition diagram, draw a class diagram showing your design. Include all the attributes and methods for each class.

5. Implement the design (in Java), and show the result of a sample run. No need to provide GUI; textual output is enough for this assignment.

Soongsil University

-2-

2011 Soo Dong Kim

You might also like