Ask your own question, for FREE!
Computer Science 19 Online
OpenStudy (anonymous):

So i am having trouble with my printTeam method i am suppose to create

OpenStudy (anonymous):

the printTeam method: Creates a string with the name of the team followed by the first and last name and position of each of the players on the team It says that fName cannot be resolved to a variable. Why is that? Also how would i also get the position? my code is: http://dpaste.com/1435248/ An example of what the printMethod will do in the program Returns: string Example: PigeonHawks John Smith Position: forward Bob Jones Position: center

OpenStudy (liammeron):

The variable "fName" is not a public variable, it's scope is limited to the "addPlayer" method. And what is the addPlayer method supposed to do? It appears to only check if all the team positions are filled, and if they are throw an error. The method never actually adds the player to any list. Your "addPlayer" method also overwrites the parameters that are passed to it, thus nullifying any reason to have them! Any parameters that you pass to it will just immediately be erased by the empty string assignments in the first three lines of the method! I'm not entirely sure how you are trying to do what you want, but the entire class needs to be fixed, it might be worth re-writing the entire class.

OpenStudy (liammeron):

Are you writing this as part of a class?

OpenStudy (anonymous):

Sorry, openstudy was acting up so i couldn't respond This is what the Team Class is supposed to include: It will contain an ArrayList of Player Objects. It will have a static variable that keeps track of the number of players that have been added to the team and a static method that returns the value of this variable. Provide a constructor and a method to addPlayer, a method to printTeam and a toString method. This what the addPlayer method should do: The addPlayer method will check that there is only 1 center, 2 forwards and 2 guards at a time and will check that there are no more than 5 members of the team. The addPlayer method will return a String indicating what the error is (i.e. “There is already a center on this team”) or a null if the player was added. If attempting to name a third team, an error message will be shown my new Team Class i coded: http://dpaste.com/1435739/

OpenStudy (liammeron):

Does this work? I am rusty with Java, not having used it in a while, but it looks to my tired eyes like it should be error free. The only thing that jumps out to me is the checking in the addPlayer method, shouldn't that be '=>' instead of just '>'? Don't you want to check whether there are fewer than the allotted number of players, BEFORE assigning the player to the team? If you check it as is, the code will run, and if there are already 2 players in the position of choice, it will add players anyways, THEN throw the error. Is this by design, or do you want to check to see if a slot for that position is open, THEN add them to the roster?

OpenStudy (anonymous):

Everything works except the output isn't displaying the expectant result Yeah i changed my printMethod but the only thing wrong now is that the printTeam button in the GUI dirver won't print the team name, first & last name and Position of the players

OpenStudy (liammeron):

I'm sorry, I can't really help any further. If I were you I'd either create another thread here, or ask on a forum like this one: http://www.javaprogrammingforums.com/ I hope you find the help you need!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!