Java Reference
In-Depth Information
class Geometry . Supply suitable preconditions. Why does it make sense
to use a static method in this case?
΢΢ Exercise P8.9. Write methods
public static boolean isInside(Point2D.Double
p, Ellipse2D.Double e)
public static boolean
isOnBoundary(Point2D.Double p,
Ellipse2D.Double e)
that test whether a point is inside or on the boundary of an ellipse. Add the
methods to the class Geometry .
΢ Exercise P8.10. Write a method
public static int readInt(
Scanner in, String prompt, String
error, int min, int max)
that displays the prompt string, reads an integer, and tests whether it is
between the minimum and maximum. If not, print an error message and
repeat reading the input. Add the method to a class Input .
΢΢ Exercise P8.11. Consider the following algorithm for computing x n for an
integer n. If n<0, x n is 1/x ɨn . If n is positive and even, then x n = (x n/2 ) 2 . If
n is positive and odd, then x n = x nɨ1 –x. Implement a static method
double intPower(double x, int n) that uses this algorithm.
Add it to a class called Numeric .
΢΢ Exercise P8.12. Improve the Needle class of Chapter 6 . Turn the
generator field into a static field so that all needles share a single
random number generator.
΢΢ Exercise P8.13. Implement a Coin and CashRegister class as
described in Exercise P8.1. Place the classes into a package called money .
Keep the CashRegister Tester class in the default package.
Search WWH ::




Custom Search