Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming in Java Unit 4. Learning outcome:  LO2: Be able to design Java solutions  LO3: Be able to implement Java solutions Assessment criteria:

Similar presentations


Presentation on theme: "Programming in Java Unit 4. Learning outcome:  LO2: Be able to design Java solutions  LO3: Be able to implement Java solutions Assessment criteria:"— Presentation transcript:

1 Programming in Java Unit 4

2 Learning outcome:  LO2: Be able to design Java solutions  LO3: Be able to implement Java solutions Assessment criteria:  AC2.1: Design a Java programming solution to a given problem  AC2.2: Explain the components and data and file structures required to implement a given design  AC3.3: Implement object behaviors using control structures to meet the design algorithms Learning objectives After studying this unit, you should be able to:  Understand the essentials of counter controlled repetition  Understand relational operators  Use if and if…else to choose alternative actions  Use while statement to execute statements in a program repeatedly  Use the for and do…while statements to execute statements in a program repeatedly  Use the switch statement for multiple selection  Use break and continue statements to alter the flow of control  Use logical operators to perform complex conditional expressions

3 Control structures Sequence, selection and repetition structures Sequence: The order in which you type the statements in a program, will be executed sequentially from top to bottom, unless you use some of the selection and repetition structures to have execution move to other parts of the program. Selection: Allows you to specify code to be executed depending on the outcome of a test. (If, if-else, switch statements) Repetition: Allows you to repeat certain parts of code dependent the value of a counter. (while, while-do, for)

4 Single selection Will execute only if the value of grade is larger or equal to 60. Otherwise that line of code will be skipped during execution.

5 Double selection Will test the value of grade. Since grade is set to 50, the test evaluates to false, and execution moves to the else part.

6 Counter controlled repetition The following are the elements that are needed in order to perform counter controlled repetition.  A control variable (or loop counter)  The initial value of the control variable  The increment (or decrement) by which the control variable is modified each time through the loop (also known as each iteration of the loop)  The loop-continuation condition that determines if looping should continue.

7 for repetition statement This specifies the counter controlled repetition details in a single line of code. General structure: for ( initialization; loopContinuationCondition; increment ){ //statements }

8

9 While Repetition statement initialization; while ( loopContinuationCondition ) { statement increment; }

10 Test your knowledge Attempt Self review questions and exercises from your e-book, pages 114 - 120. Toolbox  Lab exercises: 13, 14  Tutorial: 5, 6, 7, 8, 9.


Download ppt "Programming in Java Unit 4. Learning outcome:  LO2: Be able to design Java solutions  LO3: Be able to implement Java solutions Assessment criteria:"

Similar presentations


Ads by Google