aspose file tools*
The moose likes Beginning Java and the fly likes creating a list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "creating a list" Watch "creating a list" New topic
Author

creating a list

brent carter
Ranch Hand

Joined: Dec 15, 2011
Posts: 34
I have a list of items that I keep track of in a method in my character class. In another class, I want to be able to print out and keep track of whichever of those items i still have in that method in the character class. In other words, if i have an apple, banana, and orange, I want to have a code that can scan my list of items, see which ones i have and register those in this new class. here is my code. There is a good chance this simply involves making a list, but I don't think I have learned to do that and for some reason the internet is so hard to find the answer to simple questions.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Don’t call a class Character, because there already is a class of that name in the java.lang package.
brent carter
Ranch Hand

Joined: Dec 15, 2011
Posts: 34
thanks, that asnwered another question I had of why it made me specifically import that class
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

I'm not sure I understand. From what I gather, you want to insert something at line 35 that will display a list of available items in the Character class. Right?

Your items() method is currently just assigning values to variables. Is that your current "list"? If so, what do the values of '1' represent? Are these quantities (e.g., how many mpotions are available)? What exactly would you want returned from that example?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

(Meanwhile, here is an introduction to Java Lists, Sets, Maps, etc... Java Tutorial - Collection Interfaces.)
brent carter
Ranch Hand

Joined: Dec 15, 2011
Posts: 34
ive done some more reading and figured out how to make an array and solve this problem. I am not going to even bother posting my further questions about arrays because I know that I will figure this stuff out on my own as I keep reading. Thanks for the help guys.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Why have you got so many fields in that class? Why have you given them public access?
brent carter
Ranch Hand

Joined: Dec 15, 2011
Posts: 34
ritchie if i dont make them public, my other classes dont recognize them
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

brent carter wrote:ritchie if i dont make them public, my other classes dont recognize them

See Java Encapsulation.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
You should give the other classes access via getXXX() methods.
 
Don't get me started about those stupid light bulbs.
 
subject: creating a list