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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 2 of 2

Thread: How to keep track of %

  1. #1
    Member
    Join Date
    Feb 2014
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to keep track of %

    I'm trying to make a canteen class that holds water. It holds two quarts of water and two quarts is 100%.

    public double maxVolume;
    public int percentFull;

    Right now the Canteen is empty.

    public void Canteen()
    {
         percentFull=0;
         maxVolume=0;
     }

    And right now I'm trying to make a constructor that specifies the amount of liquid the canteen can hold and specifies the percent full.

    public Canteen(double maxVolume, int percentFull) 
    {
    }

    Should I make this second Canteen an integer, a double, or something else? Also, how do I make sure the Canteen never reaches higher than 100%. I'm also curious how I can keep maxVolume and percentFull connected so the % of water is consistent with the number of quarts(2) the Canteen can hold.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How to keep track of %

    What second Canteen? Oh, I think you mean the second Canteen() constructor, right? No, that doesn't quite fit in the question.

    Anyway, the Canteen class will have instance variables, maybe some constants. The maxVolume could be a constant, final double MAX_VOLUME. I suggest double so that division to real numbers can be done. The default constructor (no parameters) will set the variables to default values, the second constructor will set the instance variables to the parameter values passed to the constructor.

    Why don't you finish sketching out the class and the constructors and come back when you can post that and ask more questions.

Similar Threads

  1. [SOLVED] Track Mouse Movements
    By mds1256 in forum AWT / Java Swing
    Replies: 2
    Last Post: November 22nd, 2013, 06:37 AM
  2. How cookies are used to track a session?
    By Chicharito in forum Java Servlet
    Replies: 1
    Last Post: June 9th, 2013, 01:04 PM
  3. How To Track A Moving Object
    By mahdi.nikoo in forum Algorithms & Recursion
    Replies: 7
    Last Post: November 2nd, 2012, 01:03 PM
  4. [SOLVED] Keeping Track
    By Nuggets in forum Loops & Control Statements
    Replies: 2
    Last Post: April 15th, 2012, 05:37 PM
  5. keep track of objects
    By keep smiling in forum Java Theory & Questions
    Replies: 4
    Last Post: February 20th, 2012, 03:44 PM