1 / 12

Program Control using Java - Theory

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.

tedcook
Download Presentation

Program Control using Java - Theory

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

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

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

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

  5. 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 Assign Student[i] grade to ‘A’ End if End For

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

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

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

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

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

  11. Fig. 4.1 | Sequence structure activity diagram.

  12. Acknowledgements • Deitel, Java How to Program

More Related