Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
This scenario covers sports leagues where teams of players compete against each other, such as in football.
A league (e.g. English Premier League) consists of a fixed number of clubs. Throughout a season of the league each club plays each other club and the result is recorded. Each club is
awarded points for each match depending on the result, e.g. in football you get three points for winning, one for drawing and none for losing. At the end of the season the club with the
most points wins the league. If two clubs have the same number of points, they are ranked by goal difference, which is the total number of goals they have scored minus the total number of goals they have conceded.
Each club (e.g. Newcastle United) has a squad of players, the size of which may vary from club to club. For each match that the club plays a team is selected from the squad. The team is always of a fixed size e.g. eleven in football. Each player (e.g. Leon Best) has a date of birth and a height, and plays for one club. At the end of a league season, the player who has scored the most goals (i.e. has the largest goal
tally) wins the Golden Boot trophy.

Define a Java class to represent players. Provide methods to:
 create a player;
 set and get the name, date of birth and height of the player;
 add to the goal tally of a player;
 get the goal tally of a player.

Define a Java class to represent clubs. Provide methods to:
 create a club;
 set and get the name of the club;
 add to the goals-scored tally of the club;
 add to the goals-conceded tally of the club;
 get the goal difference of the club;
 add to the points tally of the club;
 get the points tally of the club;
 add a player to the squad of the club
 find out whether a player is in the club's squad;
 find the average age of the squad;
 find the average height of the squad.

Define a Java class to represent matches. Provide methods to:
 create a match;
 set and get the time and place of the match;
 set and get the clubs playing in the match;
 record which players played and how many goals each player scored;
 get the final score (e.g. Sunderland 0 – 1 Newcastle United);
 get the final result (e.g. Newcastle win).

Define a Java class to represent leagues. Provide methods to:
 create a league;
 set and get the name of the league;
 add a club to the league;
 add a fixture to the league (i.e. a match yet to be played);
 record a result in the league (i.e. add details to a match once it has been played);
 find the top team in the league;
 print out a league table;
 find the top scorer (Golden Boot) in the league.

Extend your program in the following ways:
1. Provide robust error checking, e.g. if a player is listed as scoring in a match, then they
must be in the squad of one of the clubs. Also, each player must be in only one
squad for each league.
2. Define a special type of player, the goalkeeper.
3. Find the best goalkeeper in the league. At the end of the season the best goalkeeper
is the one who has the most clean-sheets (i.e. matches in which the team concedes
no goals).

What I have tried:

I am not getting the approach to start the question. can anyone please help me with the source code.
Posted
Updated 9-Oct-22 14:16pm
v2
Comments
Dave Kreskowiak 9-Oct-22 20:11pm    
The assignment is literally telling you what to do, step-by-step. You just have to figure out how to represent the data those steps are telling you about.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
First off I suggest reading the article linked in the 1st solution. It's a pretty good article and helps in thinking about how to come to a solution.

For this specific assignment I would start by defining the classes listed in the specification. You should also define methods to test each class type. You'll need to instantiate the class and populate it and then call each method that returns a value to ensure it returns the expected value. When it doesn't, you'll want to learn how to use the debugger in your IDE if you haven't already. It is an invaluable tool to help determine where errors occur in your logic.

Once you have all the classes defined and tested go back to the top of your specification that details what the overall program is supposed to do. Break each sentence out onto its own line. Add notes to the file where you describe what code each line will turn into.

For example:
Quote:
A league (e.g. English Premier League) consists of a fixed number of clubs.
This sounds like a league has a list of clubs. When you define your League class it should probably contain a list of Club class instances.

Quote:
Throughout a season of the league each club plays each other club and the result is recorded.
You may need a Season class or perhaps a season is merely a list of matches. You'll need to think over what is the best way to meet the rest of your requirements.

Continue on like this for each line in the specification. Some lines inform you on details for one of your defined classes, others describe processing you need to do. Those that describe processing are probably methods you'll need to write to perform that task.

Once all that is done it's time to craft your main program. It has to read in the data (players, leagues, matches, etc.). Then you need to run through all the matches and record all the game results - including that of the players. Finally you need to output the required data. After each new step is added run tests to make sure the new code works. Remember those methods you wrote to test the classes as they were defined? You did write them, didn't you?

Then, after all this is working is when you start looking at what modifications you need to make to accomplish the extensions mentioned at the end of the specification. It's a good idea to keep them in mind as you work on the main solution but it's best to keep the main processing in the forefront. Coded extensions are no good if the main processing is incomplete or doesn't work.

This is a pretty big assignment. Just take it a little at a time. First read in the data. Then the next step, the next, and so on until you've completed it. As the old question goes: How can I possibly eat an entire elephant? Answer: One bite at a time.
This is what OriginalGriff's article in Solution 1 talks about. Give a read.

If you get stuck, ask another question. Show us what you've done and tell us where you're stuck. We're not big on giving away code but we're generally happy and willing to help out someone who puts in the effort. Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900