Exercises

   

graphics/icon01.gif 4.1 Suppose that we wish to modify Programs 3.7 and 4.1 to count the number of pairs of points that fall within a square of size d. First, show how to solve this problem by modifying the distance method in the implementation (so that the client does not have to be changed). Second, show how to solve this problem by changing the client to use the accessor methods in the implementation (so that the implementation does not have to be changed).

graphics/icon01.gif 4.2 Give an implementation of the point interface (Program 4.3) for points with three coordinates.

4.3 Define two points to coincide if the distance between them is less than 10-6. Add a method to the Point interface for testing whether two points coincide, then write a client program that takes an integer N from the command line and fills an array with N points, no two of which coincide.

   
Top


Algorithms in Java, Part 1-4
Algorithms in Java, Parts 1-4 (3rd Edition) (Pts.1-4)
ISBN: 0201361205
EAN: 2147483647
Year: 2002
Pages: 158

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net