aspose file tools*
The moose likes Beginning Java and the fly likes Help with some code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with some code?" Watch "Help with some code?" New topic
Author

Help with some code?

matt gilbert
Greenhorn

Joined: Jun 17, 2003
Posts: 5
public class CookPot
{
Private int capacity, material, price;
Public void getPot (int size, int metal ,int cost)
{
size=capacity;
metal=material;
cost=price;
}
}
This code is just not working they way I want it to. I think it has something to do with the variables capacity, material, price and the way they are defined.
Richard Jensen
Ranch Hand

Joined: May 14, 2003
Posts: 67
I know this isn't the real code because some of the keywords are capitalized--but do you really have the parameters to getPot on the left side of the assignment operator and the member variables on the right? If so, just swap them. If that isn't the case, maybe posting the real code and a more detailed description of the problem might be in order.


Richard
N 37 33 W 122 18
Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
hi matt,
[B]
[/B]
looking at the codes, i can tell you two things.
First, since your method name starts with get, you must be trying to get values of each of your privage variables. if this is the case, you getter method must have a return type based on variables and you must not declare a parameter list inside this getter.
Second, as you defined a parameter list, you are intending to set values to those private variables. you don't set values through getter method, but through set method. so you need to redesign your class like following:

hope this might help. you might want to take a look at some OO literature that is in sun site.
matt gilbert
Greenhorn

Joined: Jun 17, 2003
Posts: 5
do the variables size, metal and cost exist only in the scope of the getPot method?
Richard Jensen
Ranch Hand

Joined: May 14, 2003
Posts: 67
The parameters to the getPot method are 'in-scope' only in that method. The values passed to a call of that method may have a much longer lifetime. If you are trying to extract the values of your private data members into the parameters to getPot, you can't do that in Java because parameters are copies--while you can modify their value within the method, that change does not affect the actual value passed into the method call.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with some code?