Java Reference
In-Depth Information
Rewrite this code to eliminate the explicit
true
and
false
values, by
setting
xInside
and
yInside
to the values of Boolean expressions.
T Exercise R5.19 Give a set of test cases for the earthquake program in
Section 5.3.1
. Ensure coverage of all branches.
T Exercise R5.20 Give a set of test cases for the tax program in
Section
5.3.2
. Compute the expected results manually.
T Exercise R5.21 Give an example of a boundary test case for the tax
program in
Section 5.3.2
. What result do you expect?
Additional review exercises are available in WileyPLUS.
220
221
PROGRAMMING EXERCISES
Exercise P5.1. Write a program that prints all real solutions to the
quadratic equation ax
2
+ bx + c = 0. Read in a, b, c and use the quadratic
formula. If the discriminant b
2
- 4ac is negative, display a message stating
that there are no real solutions.
Implement a class
QuadraticEquation
whose constructor receives the
coefficients
a, b, c
of the quadratic equation. Supply methods
getSolution1
and
getSolution2
that get the solutions, using the
quadratic formula, or 0 if no solution exists. The
getSolution1
method
should return the smaller of the two solutions.
Supply a method
boolean hasSolutions()
that returns
false
if the discriminant is negative.
Exercise P5.2. Write a program that takes user input describing a playing
card in the following shorthand notation: