Apache web server - 306 Methods Chapter 6 6.11 Answer each of
306 Methods Chapter 6 6.11 Answer each of the following questions: a) What does it mean to choose numbers at random? b) Why is the Math.randommethod useful for simulating games of chance? c) Why is it often necessary to scale and/or shift the values produced by Math.random? d) Why is computerized simulation of real-world situations a useful technique? 6.12 Write statements that assign random integers to the variable n in the following ranges: a) 1 = n = 2 b) 1 = n = 100 c) 0 = n = 9 d) 1000 = n = 1112 e) 1 = n = 1 f) 3 = n = 11 6.13 For each of the following sets of integers, write a single statement that will print a number at random from the set: a) 2, 4, 6, 8, 10. b) 3, 5, 7, 9, 11. c) 6, 10, 14, 18, 22. 6.14 Write a method integerPower( base,exponent )that returns the value of base exponent For example, integerPower(3,4)calculates 34 (or 3*3*3*3). Assume that exponent is a positive, nonzero integer and that baseis an integer. Method integerPowershould use for or while to control the calculation. Do not use any math library methods. Incorporate this method into an applet that reads integer values from JTextFields for base and exponent from the user and performs the calculation with the integerPowermethod. [Note: Register for event handling on only the second JTextField. The user should interact with the program by typing numbers in both JTextFields and pressing Enter only in the second JTextField.] 6.15 Define a method hypotenusethat calculates the length of the hypotenuse of a right triangle when the other two sides are given (sample data appear in Fig. 6.22). The method should take two arguments of type doubleand return the hypotenuse as a double. Incorporate this method into an applet that reads values for side1and side2 from JTextFields and performs the calculation with the hypotenuse method. Determine the length of the hypotenuse for each of the following triangles. [Note: Register for event handling on only the second JTextField. The user should interact with the program by typing numbers in both JTextFields and pressing Enter only in the second JTextField.] Triangle Side 1 Side 2 1 3.0 4.0 2 5.0 12.0 3 8.0 15.0 Fig. 6.2222 Values for the sides of triangles in Exercise 6.15. Fig. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01