Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 2: Soccer Team Expansion (2 marks) Create a Python class for the expanded UML class diagram below. This now includes a Group class. Which
Task 2: Soccer Team Expansion (2 marks) Create a Python class for the expanded UML class diagram below. This now includes a Group class. Which consists of soccer teams and keeps track of all scores. Steps 1. Create the Group class and an initialiser method (constructor) that initialises attribute name, and teams as an empty list. Tip: An empty list can be created by assigning square brackets [] to a variable. Values can be added to the list by calling the .append() method. 2. Create and implement the addTeam method which takes a SoccerTeam object and adds it to the teams list. Note: This method and the attribute teams implement the aggregation relationship shown in the class diagram above. 3. Create and implement the addMatchResult method which has four parameters representing our team, the opposition team, our teams' goals and the opposition teams' goals. These teams are SoccerTeam objects that play against each other. This method should call the addResult methods of both teams. 4. Create and implement printTable which prints the name of the group and the report of each team sorted by score and goal difference. This method should call the printReport method of each team. Tip: To sort the teams according to score and goal difference, you can use the following .sort method call on the list. .sort(key=lambda team: (team.getScore(), team.goalDifference()), reverse=True) 5. Test your methods by creating an instance of the Group class. To do this, execute the following code: seoul = SoccerTeam("Seoul Dynasty") dalas = SoccerTeam("Dalas Fuel") florida = SoccerTeam("Florida Mayhem") losAngeles = SoccerTeam("Los Angeles Valiant") group = Group("OWL") group.addTeam(seoul) group.addTeam(dalas) group.addTeam(florida) Your output must match the following: Group OWL Dalas Fuel: Won: 3 Lost: 0 Draw: 0 Team Goals: 9 Opposition Goals: 2 Goal Difference: 7 Points: 9 Florida Mayhem: Won: 1 Lost: 1 Draw: 1 Team Goals: 6 Opposition Goals: 4 Goal Difference: 2 Points: 4 Seoul Dynasty: Won: 1 Lost: 1 Draw: 1 Team Goals: 4 Opposition Goals: 5 Goal Difference: -1 Points: 4 Los Angeles Valiant: Won: 0 Lost: 3 Draw: 0 Team Goals: 2 Opposition Goals: 10 Goal Difference: -8 Points: 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started