need help with a homework problem and i've been starring at code all day and my brain is fried... any advice or pointers would be greatly appreciated

Description of the Problem
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 application that reads three values from the user, determines
the smallest value and displays the result.

// Lab 1: Min.java
// Program finds the minimum of 3 numbers
import java.util.Scanner;

public class Min
{
   // find the minimum of three numbers
   public void findMinimum()
   {
      Scanner input = new Scanner( System.in );

      double one; // first number
      double two; // second number
      double three; // third number
      
      System.out.printf( "%s\n   %s\n   %s\n", 
         "Type the end-of-file indicator to terminate", 
         "On UNIX/Linux/Mac OS X type <ctrl> d then press Enter",
         "On Windows type <ctrl> z then press Enter" );
      System.out.print( "Or enter first number: " );
      
      while ( input.hasNext() )
      {
         one = input.nextDouble();

         /* Write code to get the remainder of the inputs and 
            convert them to double values */
         two = input.nextDouble();
         three = input.nextDouble();
         
         /* Write code to display the minimum of the three floating-point numbers */
         System.out.printf("Minimum is: %f ",  minValue);
         System.out.printf( "\n%s\n   %s\n   %s\n", 
            "Type the end-of-file indicator to terminate", 
            "On UNIX/Linux/Mac OS X type <ctrl> d then press Enter",
            "On Windows type <ctrl> z then press Enter" );
         System.out.print( "Or enter first number: " );
      } // end while
   } // end method findMinimum

   // determine the smallest of three numbers
   /* write the header for the minimum3 method */
   public void minimum3()
   {
      double x;
	  double y;
	  double z;
	  double minValue;
	  
	  minValue = x;
	  
	  if (minValue > y)
	     minValue = y;
		 
	  if (minValue > z)
	     minValue = z;
      // determine the minimum value
      return minValue; /* Write code to compute the minimum of the three numbers 
                using nested calls to Math.min */
   } // end method minimum3
} // end class Min

Edited 5 Years Ago by MisterSinyster: n/a

I don't see anything obviously wrong except the missing semi after the return statement and the fact that you're not using Math.min - what is the problem you're having?

Edited 5 Years Ago by jon.kiparsky: n/a

missed a few semi's but added them already.
compiler errors
line 32 - cannot find symbol : variable minValue
line 58 - cannot return a value whose result type is void

also i've never used math.min. could you give an example possibly?

Thanks, that helps.

line 32 - you're referring to a variable that doesn't exist at this point. minValue is local to the minimum3 method. You'll fix that by fixing that method to return a value, and then using that value.

line 58 - minimum3 is declared to return no value. Change "void" to "double" and you'll be required to return a value. Once you've done that, replace "minValue" at line 32 with the call to that method:

System.out.printf("Minimum is: %f ",minimum(one, two, three));

As for math.min, it's a function of two arguments and it returns the lesser of the two. For more information, look at the API documentation for the Math class.

This article has been dead for over six months. Start a new discussion instead.