Chapter 3 Introduction to Java Applets 147 (Web hosting ecommerce) 3.12
Chapter 3 Introduction to Java Applets 147 3.12 Write an applet that reads in two floating-point numbers and determines and prints if the first is a multiple of the second. (Hint: Use the modulus operator.) Use only the programming techniques you learned in this chapter and Chapter 2. Draw the results on the applet. 3.13 Write an applet that draws a checkerboard pattern as follows: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 3.14 Write an applet that draws a variety of rectangles of different sizes and locations. 3.15 Write an applet that allows the user to input the four arguments required by method draw- Rect, then draws a rectangle using the four input values. 3.16 The Graphics class contains a drawOval method that takes the same four arguments as method drawRect. However, the arguments for method drawOval specify the bounding box for the oval. The sides of the bounding box are the boundaries of the oval. Write a Java applet that draws an oval and a rectangle with the same four arguments. You will see that the oval touches the rectangle at the center of each side. 3.17 Modify the solution to Exercise 3.16 to output a variety of ovals of different shapes and sizes. 3.18 Write an applet that allows the user to input the four arguments required by method draw- Oval, then draws an oval using the four input values. 3.19 What does the following code print? g.drawString( “*”, 25, 25 ); g.drawString( “***”, 25, 55 ); g.drawString( “*****”, 25, 85 ); g.drawString( “****”, 25, 70 ); g.drawString( “**”, 25, 40 ); 3.20 Using only programming techniques from Chapter 2 and Chapter 3, write an applet that cal culates the squares and cubes of the numbers from 0 to 10 and draws the resulting values in table format as follows: number square cube 0 0 0 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 1000 [Note: This program does not require any input from the user.] Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01