Download presentation
Presentation is loading. Please wait.
Published byArthur McGee Modified over 7 years ago
1
COURSE OUTLINE INTRODUCTION DATA TYPES AND LIBRARIES
CONTROL STATEMENTS ARRAY CODING IN CLASSES GUI AND COMPONENT PROGRAMMING ALGORITHM & DATA STRUCTURE IN JAVA FILE I/O IN JAVA OOP FEATURES RECURSIVE PROGRAMMING IN JAVA
2
Chapter Three CONTROL STATEMENTS IN JAVA cont’d
Definition Control Statements are instructions that caused diversion in the normal flow of program execution. That is, they cause a kind of branching away from the normal pattern of code execution. ….more def…???
3
Chap3 CONTROL STATEMENTS IN JAVA cont’d
2nd Definition Control Statements can also be programmatically defined as statements or codes that truncate the normal flow of program execution. ….how…???
4
Chap3 CONTROL STATEMENTS IN JAVA cont’d
Response to how….they cause truncation in prog flow ….either by BRANCHING, OR ….they cause a LOOP ….so,…
5
Chap3 CONTROL STATEMENTS IN JAVA cont’d
TYPES: SELECTION C.S. (BRANCHING) & ITERATION C.S. (LOOPING) ….details now…
6
Chap3 CONTROL STATEMENTS IN JAVA cont’d
SELECTION C.S. A type of Control Statement that causes branching in the flow of program execution. In this control is transferred depending on the outcome of the conditional statement attached/specified. ….tell me more…
7
Chap3 CONTROL STATEMENTS IN JAVA cont’d
SELECTION C.S. Simply calls it a DECISION Control Statement. It decides/judges based on the parameters supplied/fed in as conditions. ….types…???
8
Chap3 CONTROL STATEMENTS IN JAVA cont’d
SELECTION C.S. – Types – Type 1 If Statement (A one-option-one-or-none executed statement) If (conditional statement) executional statement; ….illustrate? No ! Refer CSC212…NEXT???
9
Chap3 CONTROL STATEMENTS IN JAVA cont’d
SELECTION C.S. – Types – Type 2 If-else Statement (A two-options-one executed statement) If (conditional statement) executional statement I; else executional statement II; ….illustrate? No ! Refer CSC212…NEXT???
10
Chap3 CONTROL STATEMENTS IN JAVA cont’d
SELECTION C.S. – Types – Type 3 If-else-if Statement (A multi-options-one executed statement) If (conditional statement I) executional statement I; else if(conditional statement II) executional statement II; else executional statement III; ….illustrate? No ! Refer CSC212…NEXT???
11
Chap3 CONTROL STATEMENTS IN JAVA cont’d
SELECTION C.S. – Types – Type 4 Switch-Case Statement (A multi-options-one executed statement) Switch(inputted/focus variable){ Case 1: executional statement I; break; Case 2: executional statement II; . default: ….any instructional code goes here } ….illustrate? No ! Refer CSC212…NEXT???
12
Chap3 CONTROL STATEMENTS IN JAVA cont’d
ITERATIVE C. S. A type of control statement that causes a particular set of codes or a segmental part of a program to be repeatedly executed. ….is that all…??? No, more def….
13
Chap3 CONTROL STATEMENTS IN JAVA cont’d
ITERATIVE C. S. It can also be described as the type of control statement that triggers a set of actions into a continual rotational form until there occurred a counter trigger to stop them. ….types now…
14
Chap3 CONTROL STATEMENTS IN JAVA cont’d
ITERATIVE C. S. – Types – Type I Do-While (A post-test looping statement) Do{ executable statement(s); }While (conditional statement); ….illustrations? No, Refer CSC212! Next???
15
Chap3 CONTROL STATEMENTS IN JAVA cont’d
ITERATIVE C. S. – Types – Type II While (A pre-test looping statement) While(conditional statement){ executable statement(s); } ….illustrations? No, Refer CSC212! Next???
16
Chap3 CONTROL STATEMENTS IN JAVA cont’d
ITERATIVE C. S. – Types – Type III For (A range-specified looping statement) For(initial val; conditional val; incremental specification){ executable statement(s); } ….illustrations? No, Refer CSC212! But….
17
Chap3 CONTROL STATEMENTS IN JAVA cont’d
ITERATIVE C. S. – Types – Type III cont’d We have – 1st Type of FOR NESTED FOR (a FOR statement embedded in another FOR statement) For(int i=1,i<11,i++){ For(int j=1,j<5,j++) ….next….???
18
Chap3 CONTROL STATEMENTS IN JAVA cont’d
ITERATIVE C. S. – Types – Type III cont’d 2nd Type of FOR ENHANCED FOR (a FOR statement used for accessing and manipulating array elements) For(declaration: array name) Declaration talks about the loop variable and its type. Array name implies the array in use. ….illustration….??? Yes…….let’s see one…
19
Chap3 CONTROL STATEMENTS IN JAVA cont’d
ITERATIVE C. S. – Types – Type III cont’d 2nd Type of FOR – Code Illustration public class ……{ public static void main(String[] args) { int[] myscores = {65, 75,81, 90, 76}; System.out.print("Outputting my scores in this semester: "); for(int i: myscores){ System.out.printf("\n%d",i); } ….next…tending to conclusion….but b4 then…
20
Q1 Chap3 Exercises ….next…Q2….
Using Switch statement alongside GUI for your inputting, write a java program that allows a user’s intension to be made known during input operation by inputting [1-5] where the followings are the output/message signals: Outputs – ‘you want to input data’ Outputs – ‘you are about deleting a data’ Outputs – ‘are you sure you want to delete’ Outputs – ‘you are performing an operation’ Outputs – ‘Exit application’ Outputs – ‘data out of range’ ….next…Q2….
21
Q2 Chap3 Exercises ….next…Q3….
A store contains Apples, Mangoes, and Pawpaw, each with varying types of fruits; for instance, for Apples, we have 35 Green Apples, 47 Red Apples, and 71 Hybrid Apples. Mangoes: We have 13 Red Mangoes, 17 Cherished, and 18 Savannah Mangoes. 65 Ripe Pawpaw, and 33 Unripe Pawpaw. Without using array, but JOptionPane, captures, computes and outputs for the : Total no of each classification of Fruits, and The sum total of all fruits presented. ….next…Q3….
22
Chap3 Exercises Q3 Suppose number is a variable of type integer that has been given a value. Write a multi-branch if-else statement that displays the word High if number is greater than 10, Low if number is less than 5, and So-so if number is anything else. ….next…END OF LECTURE….
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.