Assignment 1 due 2/25

CS262 – Assignment 1
Due: Thursday February 25, 2010 – 11:30am
For this assignment, you will model the behavior of a cruise control unit as a finite-state machine.
Prepare for the assignment



Review your class notes on finite-state machines, testing, and how to use the BlueJ debugger.
Read the problem description below.
Download the folder called A1 from the shared drive. In other words, copy (drag) the folder called
A1 from this location: Q:\Shared\Huen\262\Assignments onto your desktop and rename it to
include your name, like this: A1_Last_First. You must follow this naming convention precisely
(including the uppercase/lowercase letter and the underscore characters). When you have
completed the assignment, remember to submit it to the Q drive INSIDE the following folder:
Q:\Shared\Huen\262\Submit\Assignment1. Finally, also remember to make another copy to your
U drive as a backup and in between your work sessions.
Problem description
Here is an extract of the 2006 Dodge Caravan Owner’s Manual:
1
You will model the cruise control unit described in the manual using the finite-state machine whose satetransition diagram is shown below:
2
This state-transition diagram contains the following states:
OFF
The cruise control unit does not respond to any event except for the ON-OFF button.
ON
The cruise control unit is on but no target speed has been set.
ACTIVATED
The cruise control unit is engaged and is actively maintaining the set speed.
DEACTIVATED The cruise control unit is not engaged but the set speed is still memorized.
In this simplified model, the events to which the unit responds are:


the fact that one of the five buttons was pressed and released. These events are the uppercase
labels on the arrows ON-OFF, SET, COAST, RESUME-ACCEL, and CANCEL), and
the fact that the brake pedal was pushed.
Your task
In BlueJ, open up the folder that you downloaded. You must develop a CruiseControl class that
implements this FSM, using the same conventions as in the in-class and quiz examples (e.g., using named
constants for the states). The code that you downloaded will not compile until you write your new class. In
this class, you need to write (at least) one method for each event and responsible for updating the state of
the unit. Since the state-transition diagram does not include actions (only events) on the arrows, each one of
your methods must print a one-line statement describing the event or action. See below for a sample
session, which your output must match EXACTLY (character for character). Note that each method call
ALWAYS prints a message, even when the corresponding event is not listed in the state-transition diagram
for the current state, meaning that the event has no effect in that state. The following session is the result of
executing the test scenario included in the code that you downloaded:
Starting the test...
Braking does not affect the cruise control unit when it is in the OFF state
Cruise control unit is now on
Braking does not affect the cruise control unit when it is in the ON state
Pressing the RESUME/ACCEL button has no effect when the cruise control unit is in the ON state
Cruise control unit is activated.
Increasing speed
Decreasing speed by coasting
Deactivating cruise control
Braking deactivates cruise control
Pressing the CANCEL button has no effect when the cruise control unit is in the DEACTIVATED state
Re-activating cruise control
Cruise control unit is now off
You may not modify the code in the Cruise Control Test class.
What to submit
To get full credit, you must correctly solve the problem and complete all of the following tasks before the
deadline:





Test your program fully, using the test scenario that I gave you, as well as others that you should
come up with.
Your code must contain comments for the whole class and each method, as well as comments on
the closing braces of methods and big blocks, etc. You must also follow the coding style described
on the course web page (indentation, class names, etc.).
Your comments must follow the javadoc convention. Check your documentation with the
Tools>”Toggle Documentation View” or (ctrl+j).
Print the source code for your CruiseControl class, staple it, make sure that it is legible (your lines
should NOT wrap around at the right of the page by breaking up long statements and using
landscape mode in printing), and that it contains your name. Submit this hard copy to the
instructor, either in class, or in person.
Finally, copy your final A1_Last_First folder into both the Q and U drives (see above).
3
There is no need to demo your program. I will run it when I grade it. Your submission must be a BlueJ
project. Remember to test it fully before submitting it. I will use the time stamp on your electronic
submission to check when you submitted it.
Good luck and have fun!
4