Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29
Like Tree1Likes

Thread: Custom method logic help

  1. #21
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Custom method logic help

    Ch8 Part 2
    Covering Chapter 8, User Defined Classes.
    Due at Start of Class, Monday, November 21.
    80 points possible
    Write the definition of a class, swimmingPool, to implement the proper-ties of a swimming pool.
    Your class should have static instance variables to store the
    length ( in feet), width ( in feet), depth ( in feet), the fillrate ( in gallons per minute) at which the water is filling the pool, and the rate ( in gallons per minute) at which the water is draining from the pool. Add appropriate constructors to initialize the instance variables. Also add member functions, to do the following: Determine the amount of water needed to fill an empty or partially filled pool; the time needed to completely or partially fill the pool, or empty the pool; add water or drain for a specific amount of time.
    Then, write a test (main) program that prompts the user for length, width, depth, and fillrate. Create a pool object and use your member funtions to display:
    -Length
    -Width
    -Depth
    -Fill Rate
    -Drain Rate
    -Volume of pool in gallons
    -Time to fill the pool from 0% to 100%
    -Time to fill the pool from 10% to 80%
    -Time to drain the pool from 100% to 0%
    -Time to drain the pool from 80% to 10%
    Your assignment will receive points for
    #1- proper operation (75% of grade) and
    #2- structure, commenting, and style (25% of grade).
    * Your file must begin with a comment block identifying the programmer, project, last modification date. AND a comment block (following the identification header comment), that briefly describes the purpose of the program and the primary data structures (variables and finals) employed.
    * Declarations of variables and finals (constants) must be accompanied by a brief description of purpose.
    * Major control structures, such as loops or selections, should be preceded by a block comment describing what the following code does.
    * Use a sensible, consistent pattern of indentation and other formatting style (such as bracket placement) to improve the readability of your code.
    * Identifier names (constants, variables, methods, properties, classes, etc.) should be descriptive.
    * When a final (constant) is appropriate, use a final
    (constant) instead of a "magic number". More xplicitly, any constant value other than 0 or the empty string, "", should be a named constant.
    * No column longer than 80 character

  2. #22
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Custom method logic help

    Quote Originally Posted by mwr1976 View Post
    Ch8 Part 2
    Covering Chapter 8, User Defined Classes.
    Due at Start of Class, Monday, November 21.
    80 points possible
    Write the definition of a class, swimmingPool, to implement the proper-ties of a swimming pool.
    Your class should have static instance variables to store the
    length ( in feet), width ( in feet), depth ( in feet), the fillrate ( in gallons per minute) at which the water is filling the pool, and the rate ( in gallons per minute) at which the water is draining from the pool. Add appropriate constructors to initialize the instance variables. Also add member functions, to do the following: Determine the amount of water needed to fill an empty or partially filled pool; the time needed to completely or partially fill the pool, or empty the pool; add water or drain for a specific amount of time.
    Then, write a test (main) program that prompts the user for length, width, depth, and fillrate. Create a pool object and use your member funtions to display:
    -Length
    -Width
    -Depth
    -Fill Rate
    -Drain Rate
    -Volume of pool in gallons
    -Time to fill the pool from 0% to 100%
    -Time to fill the pool from 10% to 80%
    -Time to drain the pool from 100% to 0%
    -Time to drain the pool from 80% to 10%
    Your assignment will receive points for
    #1- proper operation (75% of grade) and
    #2- structure, commenting, and style (25% of grade).
    * Your file must begin with a comment block identifying the programmer, project, last modification date. AND a comment block (following the identification header comment), that briefly describes the purpose of the program and the primary data structures (variables and finals) employed.
    * Declarations of variables and finals (constants) must be accompanied by a brief description of purpose.
    * Major control structures, such as loops or selections, should be preceded by a block comment describing what the following code does.
    * Use a sensible, consistent pattern of indentation and other formatting style (such as bracket placement) to improve the readability of your code.
    * Identifier names (constants, variables, methods, properties, classes, etc.) should be descriptive.
    * When a final (constant) is appropriate, use a final
    (constant) instead of a "magic number". More xplicitly, any constant value other than 0 or the empty string, "", should be a named constant.
    * No column longer than 80 character
    Where does it state to make howFull static? This is a key point.

  3. #23
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Custom method logic help

    isn't that what the 6th line down states????

    "Your class should have static instance variables to store the "

    I mean you correct I made them non static just private and it works fine. I just emailed my teacher to ask why they have to be static. The one question I do have if they are
    static why do the methods in the same class not have access to them?

  4. #24
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Custom method logic help

    Quote Originally Posted by mwr1976 View Post
    isn't that what the 6th line down states????

    "Your class should have static instance variables to store the "

    I mean you correct I made them non static just private and it works fine. I just emailed my teacher to ask why they have to be static. The one question I do have if they are
    static why do the methods in the same class not have access to them?
    Yes that line does state to use static variables, but I asked where does it state to do this specifically with the howFull variable? Can you study the instructions and show me where it tells you to make this variable or this concept static? If it's static then it is the same for all instances of your class, so your calculations will all come out the same -- sound familiar? Again, this is a key point for the cause of your problem.

  5. #25
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Custom method logic help

    static instance variables

    Seek clarification. You can have static variables and you can have instance variables. You cannot have static instance variables.
    Fubarable likes this.

  6. #26
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Custom method logic help

    I want to have the knowledge its way more important to me then the class or the grade. So one last question, so it being static the value is unchangeable does it make it immutable? So conceptually once its set to a value it can be changed?right?? does that also carry over from object to object? I want to make sure I understand it. Is that why my calculations are coming out wrong exactly?

    Thanks.

  7. #27
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Custom method logic help

    Final variables (constants) are unchangable.

    Static means it belongs to the class and not an individual instance (object) of that class. It can certainly be changed but all instances (objects) have access to that same variable. Unlike instance variables where each object has its own copy of the variable.

  8. #28
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Custom method logic help

    Quote Originally Posted by mwr1976 View Post
    I want to have the knowledge its way more important to me then the class or the grade. So one last question, so it being static the value is unchangeable does it make it immutable?
    static doesn't make a variable unchangeable or immutable. Rather it makes the value the same for all instances of the class. So if you change the value in one instance you change it for all instances because it becomes a variable of the class not of the object or instance (hence Junky's concern). So if howFull is the same for all instances of your pool, your fill rate will be the same for 10% full, 90%, or 100% pools.

    Make sure that this variable is not static.

  9. #29
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Custom method logic help

    thanks for the help. I laughed out loud reading this explanation because now i get your earlier comment when you said "Sound familiar?"

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 0
    Last Post: 09-12-2011, 02:06 PM
  2. Need help in logic
    By nn12 in forum New To Java
    Replies: 3
    Last Post: 03-23-2011, 07:44 PM
  3. Need help on logic
    By nn12 in forum New To Java
    Replies: 6
    Last Post: 03-10-2011, 12:06 PM
  4. [SOLVED] Writing an Iterator method in a custom list
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 02-12-2009, 06:22 AM
  5. Replies: 3
    Last Post: 10-07-2008, 12:03 AM

Posting Permissions

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