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

help printing information

johnathan smith
Greenhorn

Joined: Mar 30, 2007
Posts: 21
hi

i have a class "Club"
it contains an ArrayList, add and remove methods and a method to retrieve player details. (The code for class Club is provided below).

i want to write a new class called Main which prints out the information held about each player in the club.
is this possible and if so how would i go about achieving this?

Any help would be greatly appreciated.
Many thanks.

marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

It sounds like you might want to add a method to the Player class (or maybe just override toString) that returns the details. Then add a method to the Club class that iterates through the ArrayList and calls the new method on each Player.


"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
johnathan smith
Greenhorn

Joined: Mar 30, 2007
Posts: 21
yes, its an option
but it the long run it needs to be in a new Class main

anyidea what i can write in main to do this?

thanks
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Is remove doing what you want right now? I'm betting not. I suggested some tests the other day ...

Is that how you expect Club to behave?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
johnathan smith
Greenhorn

Joined: Mar 30, 2007
Posts: 21
thanks for the tips
im sorting the remove stuff now

do you have any clue about how to print the information about all the players held in the club? i need to do this inside the new class called main I am writing?

thanks again
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by johnathan smith:
yes, its an option
but it the long run it needs to be in a new Class main

anyidea what i can write in main to do this? ...

I'm sorry -- maybe I don't understand the question. Even if you have a separate class, you're going to need a reference to the ArrayList. And you're going to iterate through the List, and call some method on each Player to get the details you want. Something like...

What am I missing? Can you spotlight where the problems are?
[ April 02, 2007: Message edited by: marc weber ]
johnathan smith
Greenhorn

Joined: Mar 30, 2007
Posts: 21
thanks for the tips

iv tested the following code
but get a compiel error saying "cannot find symbol - class List"
do you know what the problem can be?
thank you

marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by johnathan smith:
thanks for the tips

iv tested the following code
but get a compiel error saying "cannot find symbol - class List"
do you know what the problem can be?...

Add an import statement at the top...

import java.util.List;

Also, that code was just meant as a suggestion. It assumes that your Player class will have a method like getDetails().
[ April 02, 2007: Message edited by: marc weber ]
johnathan smith
Greenhorn

Joined: Mar 30, 2007
Posts: 21
hey yer iv sorted the import

my player class doesnt have a getDetails method
if i was to write one, would all the player information held in club be printed out using the method you provided?

what sort of information would i have to put in the get detaisl method?

thanks
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by johnathan smith:
hey yer iv sorted the import

What does that mean?

Originally posted by johnathan smith:
...my player class doesnt have a getDetails method
if i was to write one, would all the player information held in club be printed out using the method you provided?

what sort of information would i have to put in the get detaisl method? ...

You need to decide what you want this method to do. You indicated above that you want something that "prints out the information held about each player," so I think you've answered your own question. Have you tried to write this method?
johnathan smith
Greenhorn

Joined: Mar 30, 2007
Posts: 21
i havnt started writing the method yet
does my player class need to override the toString() method?
i guess this will return a String that represents all the details of the Players?

if thats correct how do i go about putting it together?

thanks
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by johnathan smith:
i havnt started writing the method yet ... i guess this will return a String that represents all the details of the Players? if thats correct how do i go about putting it together? ...

I really think you should make an attempt at this, instead of us writing the method for you. What do you think the method should look like?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: help printing information