# QUANG NGUYEN PD: 08 CHAPTER 5: CRITICAL THINKING HW * Please excuse me of not REDOING the question 1 – 3 questions because I have lost

the file this morning as you knew and whenever I looked at those questions, I am angrily heart-broken because I indeed put a lot of efforts and times into them. Anyway, I’m really sorry and please excuse me! Statements that use Math.random() [I have chosen to also apply Random Class and Loop] to generate random numbers for each of situations: Random integer between 1 and 50 Random integer between 20 and 100 Random double between 10 and 20

} else if (age > 18 && age < 65) { System.println (“adult”). } SHOULD BE LIKE THIS: True or False expressions if size = 100. // however.out. the Logical NOT operator (!) requires weight to not to be equal to 50 if (size >= 100 || value >= 100) // THE (=) operator couldn’t stand by itself in IF statement. } else if (age > 65) { System. because logical OR operator (||) only requires 1 condition to be right */ if (weight < 50 || size > 50) // TRUE. value could be bigger or equal to 75. because OR operator accepts size > 50 if (!(value < 75)) // TRUE .out. then true statement will be executed . thus if value is NOT smaller than 75 // (SO. weight = 50. since (&&) requires both expressions must be true. //but could be coupled with other relational operator /* TRUE.Logic errors in the statements below which should display a single appropriate message for any value of age: if (age < 18) { // The application does not include the case if the age == 18 and when the age == 65 System. if (value < 100 && !(weight == 50) ) // FALSE.out. and value = 75 if (size > 50 && weight == 50) // It will execute TRUE since Logical And operator (&&) means // both expressions must be true for the condition to be true.println (“senior”).because of Logical NOT operator.println (“child”).

and size is also = 100. because expression in parenthesis is right. thus the whole condition is true .if (!(size > 100 && weight > 50 && value > 75)) // TRUE expression will be executed. because none of the conditions is right. BUT with the (!) operator if (value < 125 || weight < 76) && size == 100) // TRUE.

g. &&. the order of operations is !. because we need (int) cast since naturally. and we could apply Short Circuit Evaluation by using Logical AND NOT OR In a logical And expression. e. random () method generates numbers have decimal portion. an if-else statement can contain another if-else or if statements in an application. A compound Boolean expression can contain more than two Boolean expressions // TRUE.Applied format() method instead of println () method for displaying Math Class calculation Statement that will calculate yx Statement that will calculate |y| Statement that will calculate √ True/False with explanations The condition of an if statement must be a Boolean expression // TRUE ?A nested if statement and if-else if statement are the same // TRUE because nested statements are the statements that are placed within the same type of statements. the sequence of these random number will repeat The (double) cast is needed to generate a random integer // FALSE. then || . Expression in a switch statement must evaluate to a double // FALSE because expression in switch statement MUST evaluate to an INTEGER and use this result to determine which statements to execute Numbers generated by a computer program are actually pseudorandom // TRUE (not entirely random. && is evaluated before ! // TRUE. both operands must be true for the expression to evaluate to true // TRUE In logical expression. since at some point.

The pow () method in the Math Class is used for exponentiation // TRUE The statement x = abs (-3). will return the value 3 // TRUE. the abs () method of the Math Class could return either double or integer result depending on the input’s data type declaration A diamond shaped object represents a decision in a flowchart // TRUE . however.

  n ¾° ¾f ¯ °¾ n¾  ¾½ff¾° f½½½f ¯ ¾¾f f°f f  %f  % \$\$@ f½½nf°  ¾°°n  nf¾  f  f°  ° f   ¾ ¯  ½°°%#n #%   ¾ %f   f  %  ¾ ¯  ½°°%#f #%   ¾ %f  %  ¾ ¯  ½°°%#¾ °#%   D @   @ f¾  ½ ¾¾°¾¾      f° f    %¾     %\$\$  n @D¾°n nf° ½ f% %¯ f°¾ \$\$  ½ ¾¾°¾¯¾   n° °    %f   "%  %%\$\$ ¾°n % %  ¾  ½ ¾¾°¾¯¾   \$\$    nf-@½ f%"%  ¾ °  f  %¾  \$\$f  %\$\$@% %½ fn °#¾f°  ¾ °¾f ¯ °  \$\$ n  n½   f°f½ f \$&@D  nf¾ nf½ f%\$\$%°  ¾n° ° &\$  %  \$\$¾  %\$\$@D  nf¾ ½ ffnn ½¾¾    %"%f  %%\$\$@D nf¾ nf-@½ f ¾f ¾-@¾¯f f° \$\$% f n     f  ° ¾f ¯ °   n  .

   %"%¾      f  %% \$\$@D ½ ¾¾°   n  nf¾ °°  n° °¾¾  D@ %"%½ f  %f  \$\$  % ¾  % \$\$@D  nf¾  ½ ¾¾°°½f ° ¾¾¾ f° ¾ ¾f¾  ¾  n° °¾     .

  ½½ ¯f%%¯  °¾ f ½°°%%¯   ¾½f°.f.

D@ ff f°-@f° ¾ ¾ ¾  ¯° n¾f ¯ °¾  n  -¯ ¾ ° f  fn¯½ ½f¯f fnf½¾  f° ¯\$\$@D%° ° f° ¯ ¾°n f¾¯  ½°  ¾  °n  ¾ f° ¯°¯  ½ f @ %   %nf¾¾°  ° f ff° ¯°  \$\$  nf¾  ° %°%nf¾¾°n °ff f° ¯%% ¯   ° f ¾°¯ ¾f  n¯f½°  n¯½°   f° ½ ¾¾°nf°n°f°¯ f°  f° ½ ¾¾°¾\$\$@D f°  n f½½ .f¾¾nfnf° f ¯ °fnfnf  f ¯ °fnfnf \$\$ f ¯ °fnfnf      @ \$f¾  ½f°f°¾ @ n° °f°¾f ¯ °¯¾ f  f° ½ ¾¾°\$\$@D "° ¾ ¾f ¯ °f°  ¾ ¾f ¯ °f  ¾f¯ \$\$@D nf¾ ° ¾ ¾f ¯ °¾f  ¾f ¯ °¾f f ½fn ° ¾f¯ ½ ¾f ¯ °¾   f° ¾ ¾f ¯ °nf°n°f°f°  ¾ ¾f ¯ °¾° f°f½½nf°  ½ ¾¾°°f¾n¾f ¯ °¯¾ ff f   \$\$ nf¾  ½ ¾¾°°¾n¾f ¯ °.

nff° ¾°nf--@ °fnf°  ½ ¾¾°  ½ f° ¾¯¾    ½ ¾¾° ff  \$\$@D °nf ½ ¾¾°  ¾ ff   "\$\$@D   ½ f°¾¾"   °\$\$ .

@ ½%%¯  ° .f.

f.f¾¾¾¾  ½° °f°\$\$@D @ ¾f ¯ ° f ¾% %  ° f \$\$@D     f ¾%%¯   .

f¾¾n  °     °   ¾ ½ ° °° °½#¾ ff½  nff°  f¯° ¾f½  © n ½ ¾ °¾f n¾°°fnf\$\$@D        .