0

I have 3 class files, 2 of them contain methods. Both methods must be tested in the 3rd file. How do I do that? An example below is just one file with a method and the testing file. If I can figure out how to put that one method file in the testing file then I should be able to put the 2nd method in too.

TESTING FILE:

    public class Test {

public static void main(String[] args) {
    java.util.Scanner input = new java.util.Scanner(System.in);
    System.out.println("Enter ten numbers: ");
    double [] numbers = new double[10];
    double minimum_number;
    for(int i=0;i<10;i++)
    {
        numbers[i] =input.nextDouble();
    }

    minimum_number = min(numbers);
    System.out.println("The minimum number is: " + minimum_number);

ONE OF THE FILES WITH A METHOD:

    public class Chapter8 {
        public static double min(double[] array)
        {

            double minimum = array[0];
            for(int i=1;i<10;i++)
            {

                if (array[i] < minimum)
                {
                    minimum = array[i]; 
                }
            }
            return minimum;
        }
      }
agentmg123
  • 159
  • 2
  • 2
  • 8

2 Answers2

2

Extend the class. See example here

public class Test extends Chapter8
Community
  • 1
  • 1
9Deuce
  • 689
  • 13
  • 27
2

if they are in the same package you can call the other function directly. If not use an import statement import {package}.Chapter8

then minimum_number = Chapter8.min(numbers);

Narcil
  • 325
  • 2
  • 13
  • The import doesn't work for some reason. I used "extends" and then minimum_number = Chapter8.min(numbers); how do you put another "extends"? I cant do it with these two below public class Test extends Chapter8 && Chapter 7 public class Test extends Chapter8, Chapter 7 – agentmg123 Sep 09 '15 at 14:52