introduction to computer science i
play

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,


  1. Introduction to Computer Science I Switch Statement Software Development Activities Janyl Jumadinova 11 April, 2018

  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

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

  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

  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 opposed to the way a nested if/else structure works. 3/9

  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

  7. Switch Statement ◮ Control flow continues with the first statement following the switch block. 5/9

  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

  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

  10. Switch Summary ◮ if and if/else can test ranges of numbers using relational ( >, <, ≥ and ≤ ) and inequality (! =) operators. 6/9

  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

  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

  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

  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

  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

  16. Object-oriented Design 7/9

  17. Software Development ◮ Establishing the software requirements : what a program must accomplish. 8/9

  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

  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

  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

  21. Identifying Classes and Objects ◮ Identify the objects from the software requirements. 9/9

  22. Identifying Classes and Objects ◮ Identify the objects from the software requirements. ◮ Decide what is an object and what is an attribute of another object. 9/9

  23. Identifying Classes and Objects ◮ Identify the objects from the software requirements. ◮ Decide what is an object and what is an attribute of another object. ◮ Decide if need to have supporting class(es), in addition to classes that represent objects. 9/9

  24. Identifying Classes and Objects ◮ Identify the objects from the software requirements. ◮ Decide what is an object and what is an attribute of another object. ◮ 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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend