help fixing error in constructor
public class Driver
{
public static void main(String[] args)
{
double distance = 400.48;
double fuel = 21.4;
AutoTrip myTrip = new AutoTrip(distance, fuel);
System.out.print("My car traveled " + myTrip.getDistance() + " miles ");
System.out.println("on " + myTrip.getFuel() + " gallons of gasoline.");
double mileage = myTrip.getMPG(); // get miles per gallon
System.out.println("My mileage was " + mileage + ".");
}
}
now here is where I get the error:
public class AutoTrip{
public double distance;
public double fuel;
public Autotrip(double miles, double gallons){
distance=miles;
fuel=gallons;
}
public double getDistance(){return distance;}
public double getFuel(){return fuel;}
public double getMPG(){return (distance/fuel);}
}
Its says invalid method declaration, return type required for line 4.
I dont see the error though...any help would be really appreciated
Re: help fixing error in constructor
nevermind, looking back at it again I see it! those type mistakes really get you in java!
Re: help fixing error in constructor
In future, post your code in code tags to make your code easier to understand and maintain its formatting so you get faster responses.
Regards, James.
Re: help fixing error in constructor
[code]your code here[/code]