Web design course - 146 Introduction to Java Applets Chapter 3 b)
146 Introduction to Java Applets Chapter 3 b) If class Double provides method parseDouble to convert a Stringto a double and class Integer provides method parseIntto convert a String to an int, then class Floatprobably provides method to convert a String to a float. c) Data type declares a double-precision floating-point variable. d) The or a browser can be used to execute a Java applet. e) To load an applet into a browser you must first define a(n) file. f) The and HTML tags specify that an applet should be loaded into an applet container and executed. 3.5 State whether each of the following is true or false. If false, explain why. a) All browsers support Java 2. b) When using an import of the form javax.swing.*, all classes in the package are imported. c) You do not need import statements if the full package name and class name are specified each time you refer to a class in a program. 3.6 Write an applet that asks the user to enter two floating-point numbers, obtains the two numbers from the user and draws the sum, product (multiplication), difference and quotient (division) of the two numbers. Use the techniques shown in Fig. 3.12. 3.7 Write an applet that asks the user to enter two floating-point numbers, obtains the numbers from the user and displays the larger number followed by the words islarger as a string on the applet. If the numbers are equal, print the message Thesenumbersareequal. Use the techniques shown in Fig. 3.12. 3.8 Write an applet that inputs three floating-point numbers from the user and displays the sum, average, product, smallest and largest of these numbers as strings on the applet. Use the techniques shown in Fig. 3.12. 3.9 Write an applet that inputs from the user the radius of a circle as a floating-point number and draws the circle s diameter, circumference and area. Use the value 3.14159 for p. Use the techniques shown in Fig. 3.12. [Note: You may also use the predefined constant Math.PI for the value of p. This constant is more precise than the value 3.14159. Class Math is defined in the java.lang package, so you do not need to import it.] Use the following formulas (r is the radius): diameter = 2r circumference = 2pr area = pr2 3.10 Write an applet that draws a box, an oval, an arrow and a diamond using asterisks (*) as follows: ********* *** * * * * * * *** * * * * * * ***** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ********* *** * * 3.11 Write an applet that reads five integers and determines and prints the largest and smallest integers in the group. Use only the programming techniques you learned in this chapter and Chapter 2. Draw the results on the applet. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01