# Program Control using Java - Theory - PowerPoint PPT Presentation

1 / 12

Department of Computer and Information Science, School of Science, IUPUI. Program Control using Java - Theory. Dale Roberts, Lecturer Computer Science, IUPUI E-mail: droberts@cs.iupui.edu. Algorithms. Algorithms is the are part of the problem solving process ‘A’ in ST A IR.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

Program Control using Java - Theory

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

#### Presentation Transcript

Department of Computer and Information Science,School of Science, IUPUI

## Program Control using Java- Theory

Dale Roberts, Lecturer

Computer Science, IUPUI

E-mail: droberts@cs.iupui.edu

### Algorithms

• Algorithms is the are part of the problem solving process

• ‘A’ in STAIR.

• All computing problems can be solved by executing a series of actions in a specific order, called an algorithm

• Algorithm: procedure in terms of

• Actions to be executed

• The order in which these actions are to be executed

• Program control

• Specify order in which statements are to executed

### Definition of Algorithm

• Definition of an Algorithm

• consists of unambiguous & computable operations

• produce a result

• halt in a finite amount of time.

• Some scientists add a restriction that the algorithm must halt in a reasonable amount of time. Why would there be resistance to this idea?

### Control Structures

• Sequential execution

• Statements executed one after the other in the order written

• Transfer of control

• When the next statement executed is not the next one in sequence

• Overuse of goto statements led to many problems

• Bohm and Jacopini

• All programs written in terms of 3 control structures

• Sequence structures: Built into C. Programs executed sequentially by default

• Selection structures: Java has three types: if, if/else, and switch

• Repetition structures: Java has three types: while, do/while and for

### Pseudocode

• Pseudocode

• An informal language similar to English

• Helps programmers develop algorithms

• Does not run on computers

• Should contain input, output and calculation actions

• Should not contain variable declarations

For each student i in the Class

Calculate the student’s average score

If the average score >= 90A% Then

End if

End For

### Control Structures

• Sequential execution

• Statements are normally executed one after the other in the order in which they are written

• Transfer of control

• Specifying the next statement to execute that is not necessarily the next one in order

• Can be performed by the goto statement

• Structured programming eliminated goto statements

### 4.4  Control Structures (Cont.)

• Bohm and Jacopini’s research

• Demonstrated that goto statements were unnecessary

• Demonstrated that all programs could be written with three control structures

• The sequence structure,

• The selection structure and

• The repetition structure

### 4.4  Control Structures (Cont.)

• UML activity diagram (www.uml.org)

• Models the workflow (or activity) of a part of a software system

• Action-state symbols (rectangles with their sides replaced with outward-curving arcs)

• represent action expressions specifying actions to perform

• Diamonds

• Decision symbols (explained in Section 4.5)

• Merge symbols (explained in Section 4.7)

### Control Structures

• Flowchart

• Graphical representation of an algorithm

• Drawn using certain special-purpose symbols connected by arrows called flowlines

• Rectangle symbol (action symbol):

• Indicates any type of action

• Oval symbol:

• Indicates the beginning or end of a program or a section of code

• Single-entry/single-exit control structures

• Connect exit point of one control structure to entry point of the next (control-structure stacking)

• Makes programs easy to build

### 4.4  Control Structures (Cont.)

• Small circles

• Solid circle represents the activity’s initial state

• Solid circle surrounded by a hollow circle represents the activity’s final state

• Transition arrows

• Indicate the order in which actions are performed

• Notes (rectangles with the upper-right corners folded over)

• Explain the purposes of symbols (like comments in Java)

• Are connected to the symbols they describe by dotted lines

### Acknowledgements

• Deitel, Java How to Program