Results 1 to 4 of 4
  1. #1
    katiebear128 is offline Member
    Join Date
    Sep 2011
    Posts
    54
    Rep Power
    0

    Default 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

  2. #2
    katiebear128 is offline Member
    Join Date
    Sep 2011
    Posts
    54
    Rep Power
    0

    Default Re: help fixing error in constructor

    nevermind, looking back at it again I see it! those type mistakes really get you in java!

  3. #3
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    4

    Default Re: help fixing error in constructor

    In future, post your code in
    Java Code:
      
    code tags to make your code easier to understand and maintain its formatting so you get faster responses.

    Regards, James.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: help fixing error in constructor

    [code]your code here[/code]

Similar Threads

  1. Constructor Error
    By collwill in forum New To Java
    Replies: 1
    Last Post: 03-20-2011, 09:16 PM
  2. Constructor Error ?
    By sysout in forum New To Java
    Replies: 4
    Last Post: 08-25-2009, 06:39 AM
  3. [SOLVED] I need help fixing an error
    By leonardjr in forum New To Java
    Replies: 8
    Last Post: 02-21-2009, 09:33 PM
  4. help with fixing my assignment.please...error
    By Jin-enigma-PL in forum New To Java
    Replies: 4
    Last Post: 02-05-2009, 01:12 AM
  5. Exception Error need help fixing
    By skinnybones in forum New To Java
    Replies: 2
    Last Post: 12-03-2007, 08:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •