Reputation: 3
I am new to Stack overflow and was having issues with a newbie-program (as i am a newbie). So i guess I'll just get to the point and post my code. From this code I was hoping to get the amount of gas left as the output, but was greeted with nothing! Thanks to anyone who help!
/*
* 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;
}
}
Upvotes: 0
Views: 35
Reputation: 44740
your constructor is empty -
public AutoMobile(double GM){
this.GM = GM;
}
Upvotes: 2