Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Urgent Class Project Help !!!!!!!!!!!!!

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy Urgent Class Project Help !!!!!!!!!!!!!

    Hi I am having problems creating code for a particular part of my class project.

    In a java program all player information is to be stored in class called club. The club class must contain methods to register and remove players. The registration method consists of the club addding a unique registration number( integer) to an unregistered player ( use static field ) It should also contain a method to retrieve the players details given the ID.
    Below is my attempt but I am a bit confused

    public class Club
    {

    private static int IdOfPlayer=0;
    private ArrayList<String> arrList = new ArrayList<String>();

    private int removePlayer(int Id)
    {
    arrList.remove(Id);
    }

    private Player AddPlayer(Player player)
    {
    arrList.add(Player);
    IdOfPlayer++;
    }
    }


  2. #2
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default Re: Urgent Class Project Help !!!!!!!!!!!!!

    Please be more specific as to what is confusing you. Have you created a Player class? Your removePlayer method has a return type of int but nothing is returned; same goes for AddPlayer. The variable arrList can only have Strings added to it, so arrList.add(Player) wouldn't work for two reasons: 1) Player is not a String 2) Player is not the name of the instance of the class, rather it should be player.

  3. The Following User Says Thank You to KucerakJM For This Useful Post:

    thesoulpatchofBruce (April 10th, 2012)

  4. #3
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Urgent Class Project Help !!!!!!!!!!!!!

    Quote Originally Posted by thesoulpatchofBruce View Post
    Hi I am having problems creating code for a particular part of my class project.

    In a java program all player information is to be stored in class called club. The club class must contain methods to register and remove players. The registration method consists of the club addding a unique registration number( integer) to an unregistered player ( use static field ) It should also contain a method to retrieve the players details given the ID.
    Below is my attempt but I am a bit confused

    public class Club
    {

    private static int IdOfPlayer=0;
    private ArrayList<String> arrList = new ArrayList<String>();

    private int removePlayer(int Id)
    {
    arrList.remove(Id);
    }

    private Player AddPlayer(Player player)
    {
    arrList.add(Player);
    IdOfPlayer++;
    }
    }
    Hello thesoulpatchofBruce!
    It will help if you say what is confusing you and ask a specific question.
    But if you want to store Player objects in your ArrayList (arrList) you should "say" that, in its declaration. Now you will face a compilation error because you are trying to add a Player object in an ArrayList which stores Strings.

  5. The Following User Says Thank You to andreas90 For This Useful Post:

    thesoulpatchofBruce (April 10th, 2012)

  6. #4
    Junior Member
    Join Date
    Mar 2012
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Urgent Class Project Help !!!!!!!!!!!!!

    Hi I am really new to java and apologise for the lack of clarity so my I am indeed trying to store the Player objects using an arraylist so I should declare <Player> where there is currently <String> ??

  7. #5
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Urgent Class Project Help !!!!!!!!!!!!!

    Quote Originally Posted by thesoulpatchofBruce View Post
    Hi I am really new to java and apologise for the lack of clarity so my I am indeed trying to store the Player objects using an arraylist so I should declare <Player> where there is currently <String> ??
    Yes you should. And you should make some more changes such as the signature of your methods as post #2 says. If you don't want them to return anything you should use the keyword void.

Similar Threads

  1. Please help! Need help with class project!
    By eldeeb_hasan in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 10th, 2012, 12:30 AM
  2. .'class' expected - what to do?!?! URGENT
    By Rads23 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 17th, 2011, 06:05 PM
  3. Help please - urgent (Project due and not done) - Easy answer
    By Bagzli in forum Java Theory & Questions
    Replies: 1
    Last Post: March 2nd, 2011, 06:36 PM
  4. [SOLVED] Return randomized String to other class in project
    By Fermen in forum Collections and Generics
    Replies: 2
    Last Post: February 16th, 2011, 05:36 PM
  5. Need urgent help with my project..
    By secretsau in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 27th, 2010, 09:43 AM