Chapter 6 Methods 307 (Web hosting colocation) 6.16 Write a method
Chapter 6 Methods 307 6.16 Write a method multiple that determines for a pair of integers whether the second integer is a multiple of the first. The method should take two integer arguments and return true if the second is a multiple of the first and false otherwise. Incorporate this method into an applet that inputs a series of pairs of integers (one pair at a time using JTextFields). [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.17 Write a method isEven that uses the modulus operator to determine if an integer is even. The method should take an integer argument and return true if the integer is even and false otherwise. Incorporate this method into an applet that inputs a series integers (one at a time using a JTextField). 6.18 Write a method squareOfAsterisksthat displays a solid square of asterisks whose side is specified in integer parameter side. For example, if sideis 4, the method displays **** **** **** **** Incorporate this method into an applet that reads an integer value for side from the user at the keyboard and performs the drawing with the squareOfAsterisks method. Note that this method should be called from the applet s paint method and should be passed the Graphics object from paint. 6.19 Modify the method created in Exercise 6.18 to form the square out of whatever character is contained in character parameter fillCharacter. Thus, if side is 5 and fillCharacteris # , the method should print ##### ##### ##### ##### ##### 6.20 Use techniques similar to those developed in Exercise 6.18 and Exercise 6.19 to produce a program that graphs a wide range of shapes. 6.21 Modify the program of Exercise 6.18 to draw a solid square with the fillRect method of the Graphics class. Method fillRect receives four arguments: x-coordinate, y-coordinate, width and height. Allow the user to input the coordinates at which the square should appear. 6.22 Write program segments that accomplish each of the following tasks: a) Calculate the integer part of the quotient when integer a is divided by integer b. b) Calculate the integer remainder when integer ais divided by integer b. c) Use the program pieces developed in parts a) and b) to write a method displayDig its that receives an integer between 1and 99999 and prints it as a series of digits, each pair of which is separated by two spaces. For example, the integer 4562 should be printed as 4 5 6 2 d) Incorporate the method developed in part c) into an applet that inputs an integer from an input dialog and invokes displayDigitsby passing the method the integer entered. Display the results in a message dialog. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01