Top Banner
Programming Logic Program Design
30

Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Dec 26, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Programming Logic

Program Design

Page 2: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Objectives

• Steps in program development

• Algorithms and Pseudocode

• Data

• Activity: Alice program

Page 3: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Programming

• Development of a solution to an identified problem, and the setting up of a related series of instructions that, when directed through computer hardware, will produce the desired results.

Page 4: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Steps in development of a program

1. Define the problem

2. Outline the solution

3. Develop outline into algorithm

4. Test the algorithm

5. Code in a programming language

6. Run the program

7. Document the program

Page 5: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Algorithm

• Simple terms: a recipe

• Set of detailed, unambiguous and ordered instructions to produce desired output from a given input.

• Simple English

Page 6: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Pseudocode

• Ways to represent algorithms

• Concentrate on logic

• Conventions:– Use simple English– Separate lines– Keywords, indentation to signify control

structure– Top to bottom

Page 7: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Keywords

• Receive information– Read: input from file or record– Get: user input

• Output– Print: output to printer– Write: written to file– Display/Put: to screen

Page 8: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Program Data

• Variable: store a particular data item– Character, integer– Value changes

• Constant: data item that remain same• Data Types:

1. Integer• 3, -5, 1000

2. Character– ‘A’, ‘b’, ‘$’

3. Boolean– True or false– Control flag

Page 9: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Program data (Continued)

• Data Structures– Data items or/and data structure1. Record: data items with relationship to one another

• Student record

2. File: collection of related records.– Student file

3. Array: data structure made up of data items with same data type and are accessed by same name

– Student scores

4. String: collection of characters, fixed or variable– Student name

Page 10: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Class, Object, Method

• Class:– the abstract characteristics of a thing– White Rabbit

• Object:– A particular instance of the class– A single rabbit

• Method:– An object’s abilities or behaviors– Turning the rabbit’s head

Page 11: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Programming Implementation in Alice

Page 12: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Program Style

• Change program display styles in Preferences • How to access Preferences dialog box

– Click the Edit menu– Click the Preferences choice

• Selecting a display style in Preferences dialog– Click next to “display my program” in General tab– Select a style

• Style recommended for course: Java Style in Color

Page 13: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Program Style (continued)

Page 14: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Adding Objects to Alice

• Class: blueprint for an object • How to populate Alice world with objects

– Click Add Objects button in world window– Locate class specifying the object in the Alice Gallery– Right-click class and select “Add instance to world”

• Objects in sample world: aliceLiddell and whiteRabbit• Naming conventions for objects and classes

– Class: capitalize all words; e.g., AliceLiddell – Object: capitalize all but first word; e.g., aliceLiddell

• Objects can be renamed from the object tree

Page 15: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Adding Objects to Alice (continued)

Page 16: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Accessing Object Subparts

• Bounding box: encloses any Alice object • Impact of selecting an object in the object tree

– Bounding box is drawn around object in world window

– Details area adapts to the selected object• First action to program: Alice turns head to user• First set of programming steps

– Select + sign next to aliceLiddell in object tree– Select + sign next to neck subpart – Select head (bounding box is drawn, details change)– Drag doInOrder control to top of editing window

Page 17: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Accessing Object Subparts (continued)

Page 18: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Accessing Object Subparts (continued)

Page 19: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Sending Messages

• Programs rely on sending messages to objects

• Method: behavior-producing message

• Programming Alice’s head to turn– Select Alice Liddell’s head in the object tree– Scan through the methods in the details area– Click on pointAt()– Drag pointAt()to the editing area and drop it– Specify camera as the target

Page 20: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Sending Messages (continued)

Page 21: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Testing and Debugging

• Bug: error interfering with normal program functions

• Debugging: process of removing program bugs

• Click the Play button to test Alice Liddell application– Alice Liddell’s head will turn toward the user

Page 22: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Testing and Debugging (continued)

Page 23: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Coding the Other Actions

• say() message– Displays dialog for an object– Text can be customized by selecting other…

• Task: complete first Alice Liddell application– Add Alice Liddell’s initial greeting– Point the white rabbit to the user– Have Alice Liddell introduce herself– Have the white rabbit introduce himself

• Customize messages by selecting from more…– Example: adjust fontSize of message text to 30

Page 24: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Coding the Other Actions (continued)

Page 25: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Statements

• Statement: a line or control structure in a program

• Computer program is a collection of statements

• Basic format of a line in a program– object.message(value); more...

• Control structures manage other statements– Example: doInOrder contains other statements

Page 26: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

The Final Action

• Sequential execution– Actions are performed consecutively – Example: actions executed in doInOrder structures

• Simultaneous execution– Actions are performed in parallel– Example: actions performed in doTogether structure

• Finishing the first program– Add doTogether control structure to application– Send say( )to aliceLiddell and whiteRabbit– Message value: Welcome to our world

Page 27: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

The Final Action (continued)

Page 28: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Final Testing

• First set of actions are performed separately

• Final actions are performed simultaneously

Page 29: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Final Testing (continued)

Page 30: Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.

Questions