19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Programming</strong> Exercises 511<br />

FIGURE 13.28 (a) Four panels of geometric figures are displayed in a frame of GridLayout. (b) TicTacToe cells randomly<br />

display X, O, or nothing. (c) Exercise 13.8 draws an octagon.<br />

*13.9 (Create four fans) Write a program that places four fans in a frame of<br />

GridLayout with two rows and two columns, as shown in Figure 13.29a.<br />

*13.10 (Display a cylinder) Write a program that draws a cylinder, as shown in Figure 13.29b.<br />

(a) (b) (c)<br />

FIGURE 13.29 (a) Exercise 13.9 draws four fans. (b) Exercise 13.10 draws a cylinder. (c) Exercise 13.11 draws a diagram<br />

for function f(x) = x 2 .<br />

*13.11 (Plot the square function) Write a program that draws a diagram for the function<br />

(see Figure 13.29c).<br />

Hint: Add points <strong>to</strong> a polygon p using the following loop:<br />

f(x) = x 2 (a) (b) (c)<br />

double scaleFac<strong>to</strong>r = 0.1;<br />

for (int x = -100; x

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!