得到错误的输出

时间:2015-10-04 17:12:29

标签: java

我是Stack的新手,并且遇到了新手程序的问题(因为我是新手)。 所以我想我会直截了当地发布我的代码。 从这段代码我希望得到剩余的气体量作为输出,但没有任何问题! 感谢任何帮助过的人!

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testergasmilage;

/**
 *
 * @author zane
 */
public class Tester {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    AutoMobile car = new AutoMobile(24);
    car.fillup(20);
    car.TakeTrip(100);
    double Fuel_Left = car.reportFuel;
    System.out.println(Fuel_Left);
        // TODO code application logic here
    }
}




package testergasmilage;

/**
 *
 * @author zane
 */
public class AutoMobile {
    public double GM; // gas Milage

   public double gallons = 0;
   public double miles;
   double reportFuel;

public AutoMobile(double GM) // this is a function to declare the milage
        {
}
public void fillup (double gallons)
{
    gallons += gallons; 
}
public void TakeTrip (double miles)
{
   gallons = gallons - (miles / GM ); 
}
public double reportFuel()
{

    double Fuel_left = gallons - (miles / GM);
    return Fuel_left;
}
}

1 个答案:

答案 0 :(得分:2)

你的构造函数是空的 -

public AutoMobile(double GM){
    this.GM = GM;
}