DataSorter.java:18:错误:找不到符号

时间:2015-10-01 12:42:01

标签: java

我一直在尝试为我的AP java类开发一个程序而且我已经在一个我已经声明了所有内容的问题中运行,看起来所有东西都可以访问我需要它的地方我的同事们也不知道;这就是我所拥有的:

    import java.util.Scanner;
    /**
    This is a test class for DataSet.
    */
    public class DataSorter
    {
         public static void main(String[] args)
        {
         Scanner in = new Scanner(System.in);
         System.out.println("Please enter three numbers:");
         double num1 = in.nextDouble();
         double num2 = in.nextDouble();
         double num3 = in.nextDouble();
         DataSorter sorter = new DataSorter();



         System.out.println("The inputs in sorted order are:\n" + sorter.getSmallest() + "\n" + sorter.getMiddle() + "\n" + sorter.getLargest());
          }
   }

这里的第2课

   /**
   This class finds the smallest, middle, and largest of
   three numbers.
   */
   public class DataSet
   {
   /**
   Constructs a data set that processes three numbers.
   @param num1 the first number to sort
   @param num2 the second number to sort
   @param num3 the third number to sort
   */
   public DataSet(double num1, double num2, double num3)
   {
     num1 = dub1;
     num2 = dub2;
     num3 = dub3;

   }
    /**
    Gets the smallest number in the data set.
    @return smallest the smallest of three numbers
    */
   public double getSmallest()
  {
      double smallest = dub1;

      if(dub2 < smallest)
        smallest = dub2;

      if(dub3 < smallest)
        smallest = dub3;

      return smallest;

    }
    /**
    Gets the largest number in the data set.
    @return largest the largest of three numbers
    */
     public double getLargest()
     {
    double largest = dub1;

    if(dub2 > largest)
     largest = dub2;

    if(dub3 > largest)
     largest = dub3;

  return largest;

  }

  /**
  Gets the middle number in the data set.
  @retu rn mi ddl e the middle number of three numbers
  */
   public double getMiddle()
  {
       double middle = 0;

       middle = dub1 + dub2 + dub3 - getLargest() - getSmallest();

       return middle;


  }
   private double dub1;
   private double dub2;
   private double dub3;

 }

1 个答案:

答案 0 :(得分:1)

sorter是DataSorter类的对象。但它没有getSmallest方法。它出现在class2(数据集)

你应该制作数据集的分拣对象

  

DataSet sorter = new DataSet(num3,num3,num3);