Introduction to Computer Science I Switch Statement Software - - PowerPoint PPT Presentation

introduction to computer science i
SMART_READER_LITE
LIVE PREVIEW

Introduction to Computer Science I Switch Statement Software - - PowerPoint PPT Presentation

Introduction to Computer Science I Switch Statement Software Development Activities Janyl Jumadinova 11 April, 2018 Control Structures Java programs are built from only these seven control structures: three selection (if, if/else,


slide-1
SLIDE 1

Introduction to Computer Science I

Switch Statement Software Development Activities

Janyl Jumadinova 11 April, 2018

slide-2
SLIDE 2

Control Structures

◮ Java programs are built from only these seven control

structures:

◮ three selection (if, if/else, switch) ◮ three repetition (while, do/while, for)

◮ You implement computer algorithms by stringing sequences of

these seven control structures together.

2/9

slide-3
SLIDE 3

Selection

◮ if statement is a single-selection structure. ◮ if/else statement is a double-selection structure. 3/9

slide-4
SLIDE 4

Selection

◮ if statement is a single-selection structure. ◮ if/else statement is a double-selection structure. ◮ What if you have a series of integral values you would like to

test and you might possibly want to trigger multiple actions based on one value?

3/9

slide-5
SLIDE 5

Selection

◮ if statement is a single-selection structure. ◮ if/else statement is a double-selection structure. ◮ What if you have a series of integral values you would like to

test and you might possibly want to trigger multiple actions based on one value?

◮ A switch statement can re-implement most if or if/else

structures more compactly.

◮ You can execute more than just one action with a switch, as

  • pposed to the way a nested if/else structure works.

3/9

slide-6
SLIDE 6

Switch

char character ; switch ( character ) { case ‘a’: // case labels case ‘e’: // separated by : case ‘i’: // character case ‘o’: // notice use of ‘ ’ case ‘u’: // marks for char tests System.out.print (character+" is a lowercase vowel\n"); break; default: System.out.print (character+" is not a lowercase vowel\n"); }

4/9

slide-7
SLIDE 7

Switch Statement

◮ Control flow continues with the first statement following the

switch block.

5/9

slide-8
SLIDE 8

Switch Statement

◮ Control flow continues with the first statement following the

switch block.

◮ The break statements are necessary because without them,

statements in switch blocks fall through.

5/9

slide-9
SLIDE 9

Switch Statement

◮ Control flow continues with the first statement following the

switch block.

◮ The break statements are necessary because without them,

statements in switch blocks fall through.

◮ All statements after the matching case label are executed in

sequence, regardless of the expression of subsequent case labels, until a break statement is encountered.

5/9

slide-10
SLIDE 10

Switch Summary

◮ if and if/else can test ranges of numbers using relational

(>, <, ≥ and ≤) and inequality (! =) operators.

6/9

slide-11
SLIDE 11

Switch Summary

◮ if and if/else can test ranges of numbers using relational

(>, <, ≥ and ≤) and inequality (! =) operators.

◮ switch statement can only make exact matches of values (==). 6/9

slide-12
SLIDE 12

Switch Summary

◮ if and if/else can test ranges of numbers using relational

(>, <, ≥ and ≤) and inequality (! =) operators.

◮ switch statement can only make exact matches of values (==). ◮ switch statement works with int, char, byte, short,

String and some other special (enum) data types.

6/9

slide-13
SLIDE 13

Switch Summary

◮ if and if/else can test ranges of numbers using relational

(>, <, ≥ and ≤) and inequality (! =) operators.

◮ switch statement can only make exact matches of values (==). ◮ switch statement works with int, char, byte, short,

String and some other special (enum) data types.

◮ if and if/else can test other data types such as floating point

numbers.

6/9

slide-14
SLIDE 14

Switch Summary

◮ if and if/else can test ranges of numbers using relational

(>, <, ≥ and ≤) and inequality (! =) operators.

◮ switch statement can only make exact matches of values (==). ◮ switch statement works with int, char, byte, short,

String and some other special (enum) data types.

◮ if and if/else can test other data types such as floating point

numbers.

◮ if and if/else can find one condition to be true and execute an

action.

6/9

slide-15
SLIDE 15

Switch Summary

◮ if and if/else can test ranges of numbers using relational

(>, <, ≥ and ≤) and inequality (! =) operators.

◮ switch statement can only make exact matches of values (==). ◮ switch statement works with int, char, byte, short,

String and some other special (enum) data types.

◮ if and if/else can test other data types such as floating point

numbers.

◮ if and if/else can find one condition to be true and execute an

action.

◮ switch statements find one match and continue executing code

until a break is found.

6/9

slide-16
SLIDE 16

Object-oriented Design

7/9

slide-17
SLIDE 17

Software Development

◮ Establishing the software requirements: what a program must

accomplish.

8/9

slide-18
SLIDE 18

Software Development

◮ Establishing the software requirements: what a program must

accomplish.

◮ Creating a software design: how a program will accomplish its

requirements.

8/9

slide-19
SLIDE 19

Software Development

◮ Establishing the software requirements: what a program must

accomplish.

◮ Creating a software design: how a program will accomplish its

requirements.

◮ Implementing the design: process of writing the code

(translating design into a programming language).

8/9

slide-20
SLIDE 20

Software Development

◮ Establishing the software requirements: what a program must

accomplish.

◮ Creating a software design: how a program will accomplish its

requirements.

◮ Implementing the design: process of writing the code

(translating design into a programming language).

◮ Testing: ensuring that a program will solve the intended

problem.

8/9

slide-21
SLIDE 21

Identifying Classes and Objects

◮ Identify the objects from the software requirements. 9/9

slide-22
SLIDE 22

Identifying Classes and Objects

◮ Identify the objects from the software requirements. ◮ Decide what is an object and what is an attribute of another

  • bject.

9/9

slide-23
SLIDE 23

Identifying Classes and Objects

◮ Identify the objects from the software requirements. ◮ Decide what is an object and what is an attribute of another

  • bject.

◮ Decide if need to have supporting class(es), in addition to

classes that represent objects.

9/9

slide-24
SLIDE 24

Identifying Classes and Objects

◮ Identify the objects from the software requirements. ◮ Decide what is an object and what is an attribute of another

  • bject.

◮ Decide if need to have supporting class(es), in addition to

classes that represent objects.

◮ Assign responsibilities to each class (behaviors/methods of the

class).

9/9