Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help with my program I'm new...

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Thanked 0 Times in 0 Posts

    Default Help with my program I'm new...

    I have a program to write: Wrtie a class MPG, which has two instance variables miles and gallons, three instance methods printmpg(), setmiles(float m) and setgallons (float g) and aconstructor MPG (float m, float g).
    (i) printMPG() - calculate and prints the miles per gallon based on the values held in the instance variables miles and gallons - mpg=miles/gallons.
    (ii)set miles (float m) - set the miles i.e set miles to the value of the parameter passed
    (iii) setgallons(float g) - set the gallons i.e sets gallons to the value of the parameter passed
    (iv) MPG (Float m, float g) - the constructor which sets the instance variable miles and gallons.

    This is what I have and I dont know what to do after. I am completely lose. Please help someone...

    import java.io;
    class MPG
       //instance variable
         int miles;
         int gallons;
        MPG (float m, float g)
          miles=m; gallons=g;
            double PrintMPG()
              return miles/gallons;

    I am really really lost.. Please someone help. I know this is a simple program... Thanks...

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 636 Times in 540 Posts

    Default Re: Help with my program I'm new...

    Starting Writing a Program