Programming and Problem Solving with Java

(やまだぃちぅ) #1

202


11.Given these values for the booleanvariables x,y, and z,
x = true
y = true
z = false
indicate whether each expression is true(T) or false(F).
____a. !(y || z) || x
____b. z && x && y
____c.! y || (z || !x)
____d. z || (x && (y || z))
____e. x || x && z
12.For each of the following problems, decide which is more appropriate, an if-else
or an if. Explain your answers.
a.Students who are candidates for admission to a college submit their SAT
scores. If a student’s score is equal to or above a certain value, print a letter of
acceptance for the student. Otherwise, print a rejection notice.
b.For employees who work more than 40 hours per week, calculate overtime
pay and add it to their regular pay.
c. In solving a quadratic equation, whenever the value of the discriminant (the
quantity under the square root sign) is negative, print out a message noting
that the roots are complex (imaginary) numbers.
d.In a computer-controlled sawmill, if a cross section of a log is greater than
certain dimensions, adjust the saw to cut 4-inch by 8-inch beams; otherwise,
adjust the saw to cut 2-inch by 4-inch studs.
13.What causes the error message "UNEXPECTED ELSE"when this code fragment is
compiled?
if(mileage < 24.0)
{
System.out.print("Gas ");
System.out.print("guzzler.");
};
else
System.out.print("Fuel efficient.");
14.The following code fragment is supposed to print "Type AB"when boolean
variables typeAand typeBare both true, and to print "Type O"when both variables
are false. Instead, it prints "Type O"whenever just one of the variables is false.
Insert a { }pair to make the code segment work the way it should.
Free download pdf