240 likes | 456 Views
Activity Diagrams. What happens next?. Introduction. What are the two main parts of a computer program? Data Algorithms We have previously emphasized how real-world information can be turned into data. We will now begin to describe how the data can be analyzed and processed
E N D
Activity Diagrams What happens next?
Introduction • What are the two main parts of a computer program? • Data • Algorithms • We have previously emphasized how real-world information can be turned into data. • We will now begin to describe how the data can be analyzed and processed • An algorithm is a step-by-step set of instructions for performing some task. • An algorithm is something like an instruction manual.
Overview • Examples of everyday algorithms • A recipe for baking a cookie. • Directions to your friend on how to get to Kwik Trip. • A user manual for operating your cell phone. • Instructions for completing your tax forms. • A computer program.
Overview • In computer programming, the set of instructions must be very well defined. This involves knowing the actions that should take place and the order of those actions. • Baking: Do you mix the liquids before or after adding the flour? • Building a house: Do you put up the drywall before or after the electrical wiring work? Do you finish the landscaping before or after the plumbing work? • Business: Does a business invest in high quality furniture before or after the CEO has approved? Does the CEO approve before or after the board has approved? How does the board approve?
Describe the workflow • Example directions for cooking chocolate chip cookies: • Preheat oven to 375° F. • Combine flour, baking soda and salt in small bowl. • Beat butter, white sugar, brown sugar and vanilla extract in large bowl until creamy. • Add eggs to the creamy mixture, one at a time, beating well after each addition. • Gradually beat in flour mixture. • Stir in chocolate morsels. • Drop by rounded tablespoon onto ungreased baking sheets. • Bake for 9 to 11 minutes or until golden brown. • Cool on baking sheets for 2 minutes; remove to wire racks to cool completely.
Activity Diagram • Activity Diagrams: Activity diagrams describe the flow of an algorithm. • An activity diagram is a "model" of the flow • Activity diagrams are a type of graph. • The diagrams show the sequence of activities performed. • Activity diagrams are part of the Unified Modeling Language (UML) • Activity diagrams can show activities that are conditional or parallel
Activity Diagram Elements Eat dinner Eat dinner Snack on anchovies Study for CT100 • Simple Activity diagrams consist of: • Initial node. • Final node. • Action nodes. • Flows (sequences) given by arcs.
Details • The initial node indicates where to start • The activity described by the diagram ends with the final node. • An activity can have more than one final node. • Action nodes operate on data and pass data to other actions. • The sequence of actions is defined by the arcs of the diagram.
Setting the time of a Wristwatch Pull crown out Turn crown counterclockwise to desired time Push crown in
Conditional Actions [no exam tomorrow] [exam tomorrow] Study Waste time on Facebook • Some actions are conditional. How would you say that you need to study if you have an exam tomorrow otherwise you would waste time on Facebook? • What are the actions • What is the condition? • A diamond indicates points at which a flows split (a condition) or merge
Logging In enter user name enter user password [Cancel is clicked] [Login is clicked] Check name/password cancel login [name/password is invalid] Show desktop [name/password is valid] Show Error msg
Repetition Sometimes you would like to repeat some action. This doesn't require new diagram elements but can be expressed via actions, arcs, and conditionals.
Repetition [ending condition] repeated action [continue condition] repeated action [continue condition] [ending condition]
Example • In class exercise: • Write the diagram that says: I would like to eat a slice of pizza until I'm full and then study, watch Star Wars on Blu-ray and go to bed.