1 / 14

Flowchart for Asg3

int a,b,s. Flowchart for Asg3. Generate 2 random integers for a, b. Show question and get answer s. no. yes. s=a+b?. Draw a crying face. Draw a smiling face. End. if -- else. if (s == a+b) { // // draw a smiling face // } else { //

iolani
Download Presentation

Flowchart for Asg3

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. int a,b,s Flowchart for Asg3 Generate 2 random integers for a, b Show question and get answer s no yes s=a+b? Draw a crying face Draw a smiling face End

  2. if -- else if (s == a+b) { // // draw a smiling face // } else { // // draw a crying face // } // The rest of the // program Statement list 1 Condition Statement list 1 T Could have another if F Statement list 2 Statement list 2

  3. Disney Roller Coaster Ride Measure the kid’s height, h h < 4 No Yes Ride the roller coaster Boy or Girl? boy girl Give a Mickey Give a Mini Next Stop

  4. Disney Ride in Program h = Integer.parseInt( JOptionPane.showInputDialog(“How tall is the kid?”)); // IsBoy = true or false; if (h < 4) { if (IsBoy)// Same asif (IsBoy == true) { System.out.println(“Take a Mickey”); } else { System.out.println(“Take a Mini.”); } } // end true part of if (h < 4) else // else part of if (h < 4) { System.out.println(“You can ride!!”); } // end else part of if (h < 4) System.out.println(“Go to the next stop.”);

  5. , but not really Disney Ride in Program – OK n = Integer.parseInt( JOptionPane.showInputDialog(“How tall is the kid?”)); // IsBoy = true or false; if (h < 4) if (IsBoy)// Same asif (IsBoy == true) System.out.println(“Take a Mickey”); else System.out.println(“Take a Mini.”); else System.out.println(“You can ride!!”); System.out.println(“Go to the next stop.”);

  6. Ambiguity I saw the little girl with a binocular on the mountain top. Isawthe little girlwith a binocularon the mountain top. Isawthe little girl with a binocularon the mountain top. Isawthe little girl with a binocular on the mountain top.

  7. Boy Scout: Yes Is a kid? No Parent? Is a boy? No No Yes Yes Give a guidebook Give a badge Welcome

  8. Boy Scout: in program if (IsKid) { if (IsBoy) { System.out.println(“Take a Badge”); } } else // not a kid { if (IsParent) { System.out.println(“Take a Guidebook”); } } System.out.println(“Welcome, everybody!.”);

  9. Boy Scout: wrong program if (IsKid) if (IsBoy) System.out.println(“Take a Badge”); else // not a kid if (IsParent) System.out.println(“Take a Guidebook”); System.out.println(“Welcome, everybody!.”); if (IsKid) { if (IsBoy) { System.out.println(“Take a Badge”); } else // not a boy { if (IsParent) System.out.println(“Take a Guidebook”); } } System.out.println(“Welcome, everybody!.”);

  10. Nested if/else statement if ( condition 1 ) { if ( condition 2 ) { statement list; } else { statement list; }; statement list; } else { statement list; } Indentation indicates the level of statements.

  11. Ternary Operator (?:) if ( condition ) { return X; } else { return Y; } A = (condition ? X : Y) System.out.println(score >= 60 ? “passed” : “fail”);

  12. Another form of Nested if/else statement(Cascaded) if (points >= 640) System.out.println(“A”); else if(points >= 500) System.out.println(“B”); else if(points >= 400) System.out.println(“C”); else if(points >= 300) System.out.println(“D”); else System.out.println(“F”);

  13. Another form of Nested if/else statement(Cascaded) if (condition_1) statement_1; else if(condition_2) statement_2; else if(condition_3) statement_3; else if(condition_4) statement_4; else if(condition_5) statement_5; else if(condition_6) statement_6; if (condition_1) if(condition_2) if(condition_3) if(condition_4) if(condition_5) if(condition_6) statement_1; else statement_2; if ( condition_1 && condition_2 && condition_3 && condition_4 && condition_5 && condition_6 && ) statement_1; else statement_2;

  14. Example: (x,y) (20,40) (40,52) (50,60) (70,75)

More Related