public class MaximumFinder
1: // Fig. 6.3: MaximumFinder.java
2: // Programmer-declared method maximum.
3: import java.util.Scanner;
4:
5: public class MaximumFinder
6: {
7: // obtain three floating-point values and determine maximum value
8: public void determineMaximum()
9: {
10: // create Scanner for input from command window
11: Scanner input = new Scanner( System.in );
12:
13: // prompt for and input three floating-point values
14: System.out.print(
15: "Enter three floating-point values separated by spaces: " );
16: double number1 = input.nextDouble(); // read first double
17: double number2 = input.nextDouble(); // read second double
18: double number3 = input.nextDouble(); // read third double
19:
20: // determine the maximum value
21: double result = maximum( number1, number2, number3 );
22:
23: // display maximum value
24: System.out.println( "Maximum is: " + result );
25: } // end method determineMaximum
26:
27: // returns the maximum of its three double parameters
28: public double maximum( double x, double y, double z )
29: {
30: double maximumValue = x; // assume x is the largest to start
31:
32: // determine whether y is greater than maximumValue
33: if ( y > maximumValue )
34: maximumValue = y;
35:
36: // determine whether z is greater than maximumValue
37: if ( z > maximumValue )
38: maximumValue = z;
39:
40: return maximumValue;
41: } // end method maximum
42: } // end class MaximumFinder
43:
44: /**************************************************************************
45: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
46: * Pearson Education, Inc. All Rights Reserved. *
47: * *
48: * DISCLAIMER: The authors and publisher of this book have used their *
49: * best efforts in preparing the book. These efforts include the *
50: * development, research, and testing of the theories and programs *
51: * to determine their effectiveness. The authors and publisher make *
52: * no warranty of any kind, expressed or implied, with regard to these *
53: * programs or to the documentation contained in these books. The authors *
54: * and publisher shall not be liable in any event for incidental or *
55: * consequential damages in connection with, or arising out of, the *
56: * furnishing, performance, or use of these programs. *
57: *************************************************************************/