Download Programming in Java
Transcript
CHAPTER 4. BASIC USE OF JAVA
162
{
p = pn;
y = a;
a = (a+b)/2.0;
b = sqrt(y*b);
u = u-x*(a-y)*(a-y);
x = 2*x;
pn = a*a/u;
print(pn);
} while (pn < p);
When you have investigated this for yourself try looking for arithmetic-geometric
mean (and the cross-references from there!) in Hakmem.
Mandelbrot set (again)
Adjust the Mandelbrot set program, as considered in an earlier exercise, so that at
the start (maybe in an init method?) it allocates a 400 by 400 array of integers
all initially set to 0. Change the paint method so that it just displays colours as
recorded in this array, and have a separate thread that (a) computes values to go in
the array and (b) uses repaint at the end of each of its resolution cycles to bring
make sure that the screen is brought fully up to date then. The objective here is to
arrange that each pixel is only calculated once and that thus the paint method is
a lot quicker.
Further extension of this code would add mouse support so that (as a start) a
mouse click would cause the display to re-centre at the selected point and start
drawing again using half the previous range. Those of you who get that far are
liable to be able to design more flexible and convenient user-driven controls than
that, I expect!
Tickable exercise 7
Tick 5 was the largest single exercise. Tick 6 was a fairly easy example of getting
an Applet working. This final exercise is intended to be a reasonably manageable
one to end off the series of Java practicals.
The illustration of network code that I gave represents a minimal way of accessing a remote file.
1. Extend it so that it can be used as
java Webget URL destination
to fetch the contents of an arbitrary web document and store it on the local
disc. If an explicit destination file is not specified your program should
display the document fetched on the screen;