160 likes | 298 Views
Object-Oriented Design and Programming II. CS262 Finite State Machines. Getting Oriented. Visit the class web page to access the syllabus, slides, handouts, and grades. http://www.uwosh.edu/faculty_staff/huen/262/s10262.htm
E N D
Object-Oriented Design and Programming II CS262 Finite State Machines
Getting Oriented • Visit the class web page to access the syllabus, slides, handouts, and grades. • http://www.uwosh.edu/faculty_staff/huen/262/s10262.htm - Pick up code handouts from the shared drive on the Novell network (Soft Q drive): For example: • Q:\Shared\Huen\262\Labs\S10_Labs • Submit your work to the shared drive: For example: Q:\Shared\Huen\262\Submit\Lab01\ • Read the UWO Student Discipline Code (UWS 14) at • http://www.uwosh.edu/dean/conduct.htm • Textbook companion site: http://cs.armstrong.edu/liang/intro6e/index.html (The contents of chapters 1 through 6 were covered in CS221) • BlueJ software documentation: http://www.bluej.org/doc/documentation.html
Object-oriented analysis and design For Thursday: Review chapter 7 of our textbook • Objects • Each object has a unique identity that distinguishes it from every other object Examples: ceiling fan, subway turnstile, gumball machine, cruise control unit • Objects have state and behaviors • What is the state of an object? • What do we mean by behavior?
Classes • Similar objects are grouped in a single class • A class is a template or blueprint for all the objects that share state and behavior. • More precisely, instances (or objects) of a class share the same behaviors and the same set of states they could be in, but they have a different identity and (possibly) a different current state. • UML diagrams are used to specify state, behaviors, classes, and more.
Finite-state machines • A UML class diagram is static. • The UML also has several dynamic models. • One of them is the FSM.FSM = states + transitions (event/action) • Ceiling fan example: Pull/change speed Pull/change speed Pull/change speed Pull/changed speed High Med Off Low
Observation • A state-transition diagram is a visual representation of the logic of the FSM
One Java implementation of the ceiling fan example (Furcy) Q:\Shared\Huen\262\LectureNotes\F09 Slides\week01 Output in pulling the cord 10 times Turning slowly Turning at medium speed Turning fast Stopped turning Turning slowly Turning at medium speed Turning fast Stopped turning Turning slowly Turning at medium speed
Discussion Question: What will happen if you omit one of the break statements in CeilingFan.java?
Subway turnstile example • (From Robert C. Martin, Engineering Notebook Column, June 98) Coin/unlock Locked Unlocked turn/lock Exercise: Implement this FSM for next time
Vending Machine Example A control system has to control the amount of money dropped into a vending machine. To keep the example simple, let’s restrict the inputs: only 5 and 10 cent coins are accepted. The correct, recognized sum is 25 cents.
10 Five Fif-teen 10 5 5 5 Stop Start 5 10 5 10 Ten Twen-ty A State Machine Diagram for the vending machine counter
Table 1. Transition matrix for the vending machine counter. Inputs are in the cells
Alternative Form of the Transition Matrix Top row contains input Other rows are states
A Gumball Machine • States • No_quarter • Has_quarter • Sold • Sold-out • Actions • Insert_quarter • Eject_quarter • Turn_crank • Dispense • Refill
Initial state Not in VG Not vowel Vowel / count++ Not vowel Vowel In VG Finite System Machine for Syllable Recognizer VG: Vowel Group
SET / set current speed ON Cruise ON Ready Q0 Brake OFF OFF, SET,DEC, ACC/ null OFF How about “decelerate” and “accelerate”? Cruise Control as a Finite State Machine Controls: ON, OFF buttons. SET, (DEC, ACC) buttons.