In: Computer Science
// problem2.java import java.util.*; public class problem_a { public static void main(String[] args) { // test the smallest method System.out.print("smallest(1, 0, 2) -> "); System.out.println( smallest(1, 0, 2) ); // test the average method System.out.print("average(95, 85, 90) -> "); System.out.println( average(95, 84, 90) ); } // end main /* * smallest(double, double, double) -> double * * method is given 3 numbers, produces the smallest of the three * * examples: * smallest(1, 0, 2) -> 0.0 */ public static double smallest(double x, double y, double z) { // declare your minimum ** ENTER CODE HERE** // calculate minimum as smallest of x and y ** ENTER CODE HERE** // re-calculate minimum as smallest of minimum and z ** ENTER CODE HERE** //return your minimum ** ENTER CODE HERE** } // end smallest /* * average(double, double, double) -> double * * method is given 3 numbers, produces the smallest of the three */ public static double average(double x, double y, double z) { // declare your result ** ENTER CODE HERE** // calculate the average of x, y and z ** ENTER CODE HERE** // return your result; ** ENTER CODE HERE** } // end average } // end class problem_a
Java code:-
import java.util.*;
public class problem_a
{
// problem2.java
public static void main(String[] args)
{
// test the smallest method
System.out.print("smallest(1, 0, 2) ->
");
System.out.println( smallest(1, 0, 2) );
// test the average method
System.out.print("average(95, 85, 90) ->
");
System.out.println( average(95, 85, 90) );
} // end main
/*
* smallest(double, double, double) -> double
*
* method is given 3 numbers, produces the smallest of
the three
*
* examples:
* smallest(1, 0, 2) ->
0.0
*/
public static double smallest(double x, double y, double z)
{
// declare your minimum
double minimum=x;
// calculate minimum as smallest of x and
y
if (minimum>y)
{
minimum=y;
}
// re-calculate minimum as smallest of minimum
and z
if
(minimum>z)
{
minimum=z;
}
//return your minimum
return minimum;
} // end smallest
/*
* average(double, double, double) -> double
*
* method is given 3 numbers,calculate the average of
x, y and z
*/
public static double average(double x, double y, double z)
{
// declare your result
double
result=0;
// calculate the average of x, y and z
result=(x+y+z)/3;
// return your result;
return result;
} // end average
} // end class problem_a
Screenshot of output:-