Free web host - 308 Methods Chapter 6 6.23 Implement the following
308 Methods Chapter 6 6.23 Implement the following integer methods: a) Method celsius returns the Celsius equivalent of a Fahrenheit temperature, using the calculation C =5.0 / 9.0 * ( F - 32 ); b) Method fahrenheitreturns the Fahrenheit equivalent of a Celsius temperature, using the calculation F =9.0 / 5.0 * C + 32; c) Use these methods to write an applet that enables the user to enter either a Fahrenheit temperature and display the Celsius equivalent or enter a Celsius temperature and display the Fahrenheit equivalent. [Note: This applet will require two JTextField objects that have registered action events. When actionPerformed is invoked, the ActionEvent parameter has method getSource() to determine the GUI component with which the user interacted. Your actionPerformed method should contain an if/else structure of the form if ( actionEvent.getSource() == input1 ) { // process input1 interaction here } else { // e.getSource() == input2 // process input2 interaction here } where input1 and input2 are JTextField references.] 6.24 Write a method minimum3 that returns the smallest of three floating-point numbers. Use the Math.min method to implement minimum3. Incorporate the method into an applet that reads three values from the user and determines the smallest value. Display the result in the status bar. 6.25 An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number, because 6 = 1 + 2 + 3. Write a method perfect that determines if parameter number is a perfect number. Use this method in an applet that determines and displays all the perfect numbers between 1 and 1000. Print the factors of each perfect number to confirm that the number is indeed perfect. Challenge the computing power of your computer by testing numbers much larger than 1000. Display the results in a JTextArea that has scrolling functionality. 6.26 An integer is said to be prime if it is divisible only by 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. a) Write a method that determines if a number is prime. b) Use this method in an applet that determines and prints all the prime numbers between 1 and 10,000. How many of these 10,000 numbers do you really have to test before being sure that you have found all the primes? Display the results in a JTextArea that has scrolling functionality. c) Initially, you might think that n/2 is the upper limit for which you must test to see if a number is prime, but you need only go as high as the square root of n. Why? Rewrite the program, and run it both ways. Estimate the performance improvement. 6.27 Write a method that takes an integer value and returns the number with its digits reversed. For example, given the number 7631, the method should return 1367. Incorporate the method into an applet that reads a value from the user. Display the result of the method in the status bar. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01