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¾  ¾½ff¾°– 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  %$$@% %½ fn °#¾f°  ¾ €°¾f ¯ °  $$ n  n½   f°f½ f $&@D  nf¾ –nf½ f%$$%°  ¾n° ° –&$  €% – $$¾  %$$@D  nf¾ ½ ffnn ½¾¾    €%"%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@ ff f°-@f° ¾ ¾ ¾  ¯° n¾f ¯ °¾  n  -¯ ¾– ° f  fn¯½ ½–f¯f fnf½¾  f° ¯$$@D%° ° f° ¯ ¾°n f¾¯  ½°  ¾  °n € ¾ f° ¯°¯  ½ f @ %   %nf¾¾° – ° f ff° ¯° – $$  nf¾  ° %°%nf¾¾°n °ff f° ¯%% ¯  – ° f ¾°¯ ¾f  n¯f½°  n¯½°   f° ½ ¾¾°nf°n°f°¯ f°  f° ½ ¾¾°¾$$@D f°  n f½½ .f¾¾nfnf° f ¯ °fnfnf  f ¯ °fnfnf $$ f ¯ °fnfnf      @ $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 ¯ °¯¾ ff f   $$ nf¾  ½ ¾¾°°¾n¾f ¯ °.

nff° ¾°––nf--@ °f–nf°  ½ ¾¾°  ½ f° ¾¯¾  €  ½ ¾¾° ff  $$@D °–nf ½ ¾¾°  ¾ ff  € "$$@D   €½ f°¾¾"   °$$ .

@ ½%%¯  ° .f.

f.f¾¾¾¾ € ½° °f°$$@D @ ¾f ¯ ° f ¾% %  ° f $$@D     f ¾%%¯  € .

f¾¾n  °     ° –  ¾ ½ ° °–° °½#¾ ff½  nff°  f¯° ¾f½  © n ½ ¾ °¾f n¾°°f€nf$$@D        .

Sign up to vote on this title
UsefulNot useful