为什么代码不能从另一个类中找到这个方法?

时间:2017-12-04 13:00:19

标签: class methods boolean

我试图通过引用另一个类的方法weightReasonable(double aWeight)来检查输入数是否在要求的范围内。目前我收到了这两个错误:

WaterTankProg.java:55:错误:double无法解除引用           if(weight.weightReasonable)                     ^ WaterTankProg.java:55:错误:非法启动类型           if(weight.weightReasonable)              ^

这是一个类中的输入法:

   public static double inputTankWeight ()
    { 
        double weight = 0;
        boolean inputSuccessful = false;
        Scanner scan = new Scanner(System.in);
        while (!inputSuccessful)
        {
        System.out.print("Enter weight of the tank in kilograms when empty: ");  
        try 
        {
          weight = scan.nextDouble();
          if (weight.weightReasonable)
          inputSuccessful = true;
        }
      catch (InputMismatchException e)
      {
      scan.nextLine();
        System.out.println("You didn't enter a recognisable number.");
      }
        }
        return weight;
    }

这是另一个类中的检查方法:

public boolean weightReasonable(double aWeight)
    {
        return (aWeight > 0.0 && aWeight <= MAX_WEIGHT);
    }

真的很感激任何帮助。

谢谢!

0 个答案:

没有答案
相关问题