Your SlideShare is downloading. ×
0
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Ch05 Visual Aids
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Ch05 Visual Aids

358

Published on

Eclipse

Eclipse

Published in: Education, Sports, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
358
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Refer to page 105 in the text.
  • Refer to page 105 in the text. Relational operators are used to form Boolean expressions. Boolean expressions evaluate to true or false.
  • Refer to pages 106 and 107 in the text.
  • Refer to page 107 in the text.
  • Refer to page 108 in the text.
  • Refer to page 109 in the text.
  • Refer to pages 110 and 111 in the text. The Random class actually generates pseudorandom (like random) numbers. Java implements the Linear Congruential Method to ensure that generated numbers can be considered random for most applications.
  • Refer to page 112 in the text. Compound Boolean expressions use more than one Boolean expression to determine if a condition is true or false.
  • Refer to page 112 in the text.
  • Refer to page 112 in the text.
  • Refer to page 112 in the text.
  • Refer to page 113 in the text.
  • Refer to page 115 in the text. The diamond flowchart symbol indicates a decision.
  • Refer to page 115 in the text. The RPS flowchart illustrates the application solution. Solution steps include: 1. prompting the user for a number between 1 and 3 2. generating a random number between 1 and 3 3. comparing the generated number to the number typed by the user 4. determining a winner and displaying an appropriate message
  • Transcript

    • 1. Chapter 5 The if Statement <ul><li>Conditional control structure, also called a decision structure </li></ul><ul><li>Executes a set of statements when a condition is true </li></ul><ul><li>The condition is a Boolean expression </li></ul><ul><li>For example, the statement if (x == 5) { y = 20; } assigns the value 20 to y only if x is equal to 5. </li></ul>
    • 2. Chapter 5 Relational Operators Operator Meaning == equal &lt; less than &lt;= less than or equal &gt; greater than &gt;= greater than or equal != not equal
    • 3. Chapter 5 The if-else Statement Contains an else clause that is executed when the if condition evaluates to false. For example, the statement if (x == 5) { y = 20; } else { y = 10; } assigns the value 20 to y if x is equal to 5 or the value 10 if x is not equal to 5.
    • 4. Chapter 5 Nested if-else Statements <ul><li>Should be indented to make the logic clear. </li></ul><ul><li>Nested statement executed only when the branch it is in is executed. For example, the statement if (x == 5) { y = 20; } else { if (x &gt; 5) { y = 10; } else { y = 0; } } evaluates the nested if-else only when x is not equal to 5. </li></ul>
    • 5. Chapter 5 The if-else if Statement <ul><li>Used to decide among three or more actions. </li></ul><ul><li>Conditions must be properly ordered for the statement to evaluate as expected. For example, the statement if (x &lt; 5) { y = 20; } else if (x &lt; 10) { y = 40; } else if (x &lt; 15) { y = 80; } would give very different results if the conditions were ordered differently. </li></ul>
    • 6. Chapter 5 The switch Statement <ul><li>Used to decide among three or more actions. </li></ul><ul><li>Uses an expression that evaluates to an integer. </li></ul><ul><li>The break statement moves program execution to the next statement after the switch . </li></ul><ul><li>The default code is optional and is executed when none of the previous cases are met: switch (numLegs) { case 2: System.out.println(&amp;quot;human&amp;quot;); break; case 4: System.out.println(&amp;quot;beast&amp;quot;); break; case 8: System.out.println(&amp;quot;insect&amp;quot;); break; default: System.out.println(&amp;quot;???&amp;quot;); break; } </li></ul>
    • 7. Chapter 5 The Math Class <ul><li>Part of the java.lang package </li></ul><ul><li>The random() methods generates a double between 0 and 1.0. For example, double rNum; rNum = Math.random(); </li></ul><ul><li>A random integer in a range is generated by using the expression: (highNum – lowNum + 1) * Math.random() + lowNum </li></ul>
    • 8. Chapter 5 Compound Boolean Expressions <ul><li>More than one Boolean expression in a single condition. </li></ul><ul><li>Formed using the logical And ( &amp;&amp; ), logical Or ( || ), or logical Not ( ! ) operators. </li></ul>
    • 9. Chapter 5 And Truth Table False False False False True False False False True True True True Result Exp2 Exp1 And
    • 10. Chapter 5 Or Truth Table False False False True True False True False True True True True Result Exp2 Exp1 Or
    • 11. Chapter 5 Not Truth Table True False False True Result Exp Not
    • 12. Short Circuit Evaluation <ul><li>Java uses Short Circuit Evaluation to determine the result of a compound Boolean expression </li></ul><ul><ul><li>Left side is evaluated first </li></ul></ul><ul><ul><li>If the result of the entire expression can be determined by the value of the left operand, then no other operands will be evaluated </li></ul></ul>
    • 13. Order of Operations <ul><li>Not (!) evaluated first </li></ul><ul><li>And (&amp;&amp;) evaluated second </li></ul><ul><li>Or (||) evaluated last </li></ul>
    • 14. Quarter 2 Drill # 4 <ul><li>size=100 weight=50 value=75 </li></ul><ul><li>size &gt; 50 &amp;&amp; weight ==50 t or f? </li></ul><ul><li>size &gt; 50 || weight ==50 t or f? </li></ul><ul><li>Which one of the above can be Short Circuited? </li></ul>
    • 15. Quarter 2 Drill # 4 <ul><li>size=100 weight=50 value=75 </li></ul><ul><li>!(value&lt;75) </li></ul><ul><li>size &gt;=100 || value &gt;=100 </li></ul><ul><li>Can #2 be short circuited? </li></ul>
    • 16. Quarter 2 Drill # 4 <ul><li>size=100 weight=50 value=75 </li></ul><ul><li>value &lt; 100 &amp;&amp; !(weight==50) </li></ul><ul><li>!(size&gt;100 &amp;&amp; weight&gt;50 &amp;&amp; value&gt;75) </li></ul><ul><li>(value&lt;125 || weight&lt;76) &amp;&amp; size==100 </li></ul>
    • 17. Quarter 2 Drill # 4 <ul><li>Write the following: </li></ul><ul><li>Value not greater than 75 or size not greater than 100 </li></ul>
    • 18. Chapter 5 The Math Class <ul><li>Part of the java.lang package </li></ul><ul><li>Methods include: </li></ul><ul><ul><li>abs(num) returns the absolute value of num </li></ul></ul><ul><ul><li>pow(num1, num2) returns num1 raised to the num2 power </li></ul></ul><ul><ul><li>sqrt(num) returns the square root of num, where num is a positive number </li></ul></ul>
    • 19. Chapter 5 Flowchart Symbols decision
    • 20. Chapter 5 The RPS Flowchart

    ×