Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 829069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:49:30+00:00 2026-05-15T03:49:30+00:00

I have situation. I have to create a Sports Club system in JAVA. There

  • 0

I have situation. I have to create a Sports Club system in JAVA. There should be a class your for keeping track of club name, president name and braches the club has. For each sports branch also there should be a class for keeping track of a list of players. Also each player should have a name, number, position and salary.
So, I come up with this. Three seperate classes:

public class Team
{
String clubName;
String preName;
Branch []branches;
}

public class Branch
{
Player[] players;

}

public class Player
{
String name;
String pos;
int salary;
int number;
}

The problems are creating Branch[] in another class and same for the Player[]. Is there any simplier thing to do this? For example, I want to add info for only the club name, president name and branches of the club, in this situation, won’t i have to enter players,names,salaries etc. since they are nested in each other. I hope i could be clear. For further questions you can ask.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:49:30+00:00Added an answer on May 15, 2026 at 3:49 am

    Here’s a more complete, formal example of your scenario using conventional Accessors/Mutators (getters/setters), constructors, and Lists. The main() method below illustrates how to use your classes.

    public class SportsClub
    {
        public static void main(String[] args)
        {
            //Create a team without any branches
            Team myTeam = new Team("Southpaws", "South");
    
            //Create a new Branch without any players
            Branch myBranch = new Branch();
    
            //Add myBranch to myTeam
            myTeam.getBranches().add(myBranch);
    
            //Create a new player
            Player myPlayer = new Player("Bob", "Center", 120, 3);
    
            //Add myPlayer to myBranch (and therefore myTeam)
            myBranch.getPlayers().add(player);
        }
    }
    
    
    public class Team
    {
        private String clubName;
        private String preName;
        private List<Branch> branches;
    
        public Team(String clubName, String preName)
        {
            this.clubName = clubName;
            this.preName = preName;
            branches = new ArrayList<Branch>();
        }
    
        public String getClubName() { return clubName; }
        public String getPreName() { return preName; }
        public List<Branch> getBranches() { return branches; }
    
        public void setClubName(String clubName) { this.clubName = clubName; }
        public void setPreName(String preName) { this.preName = preName; }
        public void setBranches(List<Branch> branches) { this.branches = branches; }
    }
    
    public class Branch
    {
        private List<Player> players = new ArrayList<Player>();
    
        public Branch() {}
    
        public List<Player> getPlayers() { return players; }
        public void setPlayers(List<Player> players) { this.players = players; }
    }
    
    public class Player
    {
        private String name;
        private String pos;
        private Integer salary;
        private Integer number;
    
        public Player(String name, String pos, Integer salary, Integer number)
        {
            this.name = name;
            this.pos = pos;
            this.salary = salary;
            this.number = number;
        }
    
        public String getName() { return name; }
        public String getPos() { return pos; }
        public Integer getSalary() { return salary; }
        public Integer getNumber() { return number; }
    
        public void setName(String name) { this.name = name; }
        public void setPos(String pos) { this.pos = pos; }
        public void setSalary(Integer salary) { this.salary = salary; }
        public void setNumber(Integer number) { this.number = number; }
    }
    

    To answer your question, yes, you can create these objects without populating the Lists with players. The SportsClub.main() above illustrates that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have situation where my Java class needs to create a ton of certain
I have a situation in which there's an HTTP GET parameter with name Date
I have a situation where I want to create a signature of a data
I have a situation where I want to create a mapping from a tuple
Strange situation. If I have these tables: CREATE TABLE t1 (id INT, title VARCHAR(20),
i have situation like this: class IData { virtual void get() = 0; virtual
I have a situation where i need to create a left panel. My manager
I have a situation where I would like to create a 1-to-1 relationship in
I have a situation, where I need to create a new JavaScript object that
I have this situation in my SL4 application: We create some User Accounts in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.