Results 21 to 29 of 29
Thread: Custom method logic help
- 11-11-2011, 03:22 AM #21
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
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
-
Re: Custom method logic help
- 11-11-2011, 03:30 AM #23
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
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?
-
Re: Custom method logic help
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.
- 11-11-2011, 03:40 AM #25
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.
- 11-11-2011, 03:43 AM #26
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
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.
- 11-11-2011, 03:48 AM #27
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.
-
Re: Custom method logic help
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.
- 11-11-2011, 04:00 AM #29
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Similar Threads
-
Public API for Custom XML Parts & Custom Parts, Graphics Rendering
By sherazam in forum Java SoftwareReplies: 0Last Post: 09-12-2011, 01:06 PM -
Need help in logic
By nn12 in forum New To JavaReplies: 3Last Post: 03-23-2011, 06:44 PM -
Need help on logic
By nn12 in forum New To JavaReplies: 6Last Post: 03-10-2011, 11:06 AM -
[SOLVED] Writing an Iterator method in a custom list
By xcallmejudasx in forum New To JavaReplies: 2Last Post: 02-12-2009, 05:22 AM -
Understand my logic errors and better understanding method and class creation
By freethinker89 in forum New To JavaReplies: 3Last Post: 10-06-2008, 11:03 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks