1 / 16

Object-Oriented Design and Programming II

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

robbin
Download Presentation

Object-Oriented Design and Programming II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Object-Oriented Design and Programming II CS262 Finite State Machines

  2. 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

  3. 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?

  4. 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.

  5. 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

  6. Observation • A state-transition diagram is a visual representation of the logic of the FSM

  7. 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

  8. Discussion Question: What will happen if you omit one of the break statements in CeilingFan.java?

  9. 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

  10. 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.

  11. 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

  12. Table 1. Transition matrix for the vending machine counter. Inputs are in the cells

  13. Alternative Form of the Transition Matrix Top row contains input Other rows are states

  14. A Gumball Machine • States • No_quarter • Has_quarter • Sold • Sold-out • Actions • Insert_quarter • Eject_quarter • Turn_crank • Dispense • Refill

  15. Initial state Not in VG Not vowel Vowel / count++ Not vowel Vowel In VG Finite System Machine for Syllable Recognizer VG: Vowel Group

  16. 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.

More Related