3. Given 10 teams, design a tournament schedule by OO where each team play the o
ID: 3752485 • Letter: 3
Question
3. Given 10 teams, design a tournament schedule by OO where each team play the other 2 times. Each team can only play one game per day. The maximum number of games per day is 4, due to the limitation of the space. Please provide both the class and demo files.
Can anybody help me with this assignment program in JAVA
The program must have the following basic design:
• Team class – this class represents a team in the competition (in this program,
a country)
• Group class – this class represents a group in the World Cup competition.
Each Group object controls four Team objects
• Test driver classes – these classes will test the Team and Group classes
• GameDriver class – this class contains the main(…) method and
represents the game logic
Assignment Tasks:
Task 1: Program Design (10 marks)
As a first task it is important to understand and document the program design. Read
the whole assignment specification and draw a class diagram to represent the
program design. Include all classes, attributes, and methods required.
Task 2: Writing the Team Class (20 marks)
Write the Team class, including all attributes and methods, including a constructor,
accessors and mutators as appropriate, and a toString() method.
A team is represented with the following attributes:
• The team location (e.g. New Zealand)
• The team name (e.g. All games)
• The number of matches played
• The number of points scored (awarded based on match results)
• The team goals for (number of goals scored by the team)
• The team goals against (number of goals scored against the team)
Write a constructor that accepts a value for the location and name, and sets them
accordingly. It should set the number of matches played, team’s points, goals for and
goals against to 0 by default.
Write methods for the Team class to update the number of matches played
(incrementMatchesPlayed(…)), the match points awarded to the team
(incrementMatchPoints(…)), goals for (updateGoalsFor(…)) and goals
against (updateGoalsAgainst(…)) counters. Each of these methods should be
passed an integer value of the amount to update by.
Your toString() method should display the name of the team, the number of
points scored, and their current goals scored for and against.
You are provided with a test driver to test your Team class. The test driver expects a
Team class conforming to the description above. Ensure that your Team class tests
successfully with the given driver.
Task 3: Writing the Group Class (25 marks)
Write the Group class, including all attributes and methods, including a constructor,
accessors and mutators as appropriate, and a toString() method.
A group is represented with the following attributes:
• The group name (e.g. Group A)
• The teams in the group (represented by an array of 4 Team objects)
Write a constructor to accept a value for the group name and initialise the team array
with space for 4 Team objects.
A method called addTeam(…) will be required to add a team to the array. This
method should be passed a Team object to insert. Your Group class should be
responsible for keeping track of how many Team objects are in the teams array, to
ensure that existing teams are not accidentally replaced.
Write a method called matchPlayed(…) that accepts details of a football match,
and use these details to update the details of the two teams involved. This method
would accept as parameters which teams are involved in the match (these could be
integers), along with the number of goals scored by each team. This method will then
assign match points to each team, depending on whether they won or lost, based on
the number of goals each team scored.
Write a method called getOrderedLadder(…) that can return a String, listing the
teams in the group, in order of number of points scored. This is as per the rules
detailed in the Assignment Overview. You will need to iterate through the array of
team objects, comparing the match points that each team has.
Write another method called getStandings(…) that will perform the same actions
as the method above, but will only return the top two teams, for the “final standings”
functionality described in the Assignment Overview.
Write a toString() method which displays the name of the group, and lists the
teams in the group in any order.
The Group class also needs a way to check if all of the teams in a particular group
have played all of their matches, so the group’s standings can be accurately
displayed. You may also wish to include other methods in your Group class,
depending on how your program will operate.
You will be required to build a test driver for your Group class. This test driver must
test all of the public methods of your Group objects before you begin coding the
GameDriver class.
Task 4: Program Logic (25 marks)
Write the GameDriver class to implement all the main program logic as described in
the assignment overview. Ensure your design is modular (consideration of classes
and methods).
The GameDriver class provides a menu system to allow users to access the
functionality described in the Assignment Overview section of this specification.
The GameDriver will need to initialise two Group objects and keep them throughout
the execution of the program. The GameDriver must be able to perform the following
interactions with the two Group objects (from Assignment Overview):
• Create and add Team objects to each group, so that the teams may
participate in matches
• Input details of a World Cup match for two teams in a specified group (eg:
The team names and locations)
• Display the ladder of all of the teams in each group
Explanation / Answer
Class inplementation for teams:
package tournament.models;
public class team {
String location;
String name;
int numMatchesPlayed;
int numPointsScored;
int numGoalsFor;
int numGoalsAgainst;
///custom constructor/////////////////////
public team(String location, String name) {
super();
this.location = location;
this.name = name;
this.numMatchesPlayed = 0;
this.numPointsScored = 0;
this.numGoalsFor = 0;
this.numGoalsAgainst = 0;
}
public team() {
// TODO Auto-generated constructor stub
}
//////////mutators////////////////////////
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumMatchesPlayed() {
return numMatchesPlayed;
}
public void setNumMatchesPlayed(int numMatchesPlayed) {
this.numMatchesPlayed = numMatchesPlayed;
}
public int getNumPointsScored() {
return numPointsScored;
}
public void setNumPointsScored(int numPointsScored) {
this.numPointsScored = numPointsScored;
}
public int getNumGoalsFor() {
return numGoalsFor;
}
public void setNumGoalsFor(int numGoalsFor) {
this.numGoalsFor = numGoalsFor;
}
public int getNumGoalsAgainst() {
return numGoalsAgainst;
}
public void setNumGoalsAgainst(int numGoalsAgainst) {
this.numGoalsAgainst = numGoalsAgainst;
}
/////////////////methods//////////////////////////////////
public void incrementMatchesPlayed(int matchPlayed)
{
this.numMatchesPlayed += matchPlayed ;
}
public void incrementMatchPoints(int MatchPoints)
{
this.numPointsScored += MatchPoints;
}
public void updateGoalsFor(int GoalsFor)
{
this.numGoalsFor += GoalsFor;
}
public void updateGoalsAgainst(int GoalsAgainst)
{
this.numGoalsAgainst +=GoalsAgainst;
}
@Override
public String toString() {
return "team [name=" + name + ", numPointsScored=" + numPointsScored + ", numGoalsFor=" + numGoalsFor
+ ", numGoalsAgainst=" + numGoalsAgainst + "]";
}
}
Class implamentation for Groups:
package tournament.models;
import java.util.Arrays;
public class group {
char Name;
team[] Team = new team[4];
///////////////custom constructor//////////////
public group(char name, String teams) {
super();
Name = name;
String[] TeamNames = teams.split(" ");
for(int i=0; i<4; i++)
{
Team[i] = new team(TeamNames[i],"");
}
}
public void addTeam(team TeamTBA)
{
if (Team.length<4)
{
Team[Team.length] = TeamTBA;
}
}
public void matchPlayed(int teamOne, int teamTwo, int goalByTeamOne, int goalByTeamTwo)
{
//for team one
Team[teamOne].updateGoalsFor(goalByTeamOne);
Team[teamOne].updateGoalsAgainst(goalByTeamTwo);
Team[teamOne].incrementMatchesPlayed(1);
//for team two
Team[teamTwo].updateGoalsFor(goalByTeamTwo);
Team[teamTwo].updateGoalsAgainst(goalByTeamOne);
Team[teamTwo].incrementMatchesPlayed(1);
if (goalByTeamOne > goalByTeamTwo )
{
Team[teamOne].incrementMatchPoints(3);
}
if (goalByTeamOne < goalByTeamTwo )
{
Team[teamTwo].incrementMatchPoints(3);
}
if (goalByTeamOne == goalByTeamTwo )
{
Team[teamOne].incrementMatchPoints(1);
Team[teamTwo].incrementMatchPoints(1);
}
}
private void sortTeamsByPoints() {
team inter = new team();
for (int i=0; i<4; i++) {
for (int j=i; j<4; j++)
{
if (Team[i].getNumPointsScored() < Team[j].getNumPointsScored())
{
inter = Team[i];
Team[i] = Team[j];
Team[j] = inter;
}
}
}
}
public String getOrderedLadder() {
sortTeamsByPoints();
String result ="";
for (team t : Team ) {
result+= t.getName()+" ";
}
return result;
}
public String getStandings() {
sortTeamsByPoints();
String result ="";
for (int i=0;i<2;i++) {
result+= Team[i].getName()+" ";
}
return result;
}
@Override
public String toString() {
return "group [Name=" + Name + ", Team=" + Arrays.toString(Team) + "]";
}
}
Implememtation of GameDriver Class :
package tournament.controllers;
import java.util.Scanner;
import tournament.models.team;
public class GameDriver {
public static void main(String[] args) {
System.out.println("--------------Welcome to the worldcup----------------------");
Scanner input = new Scanner(System.in);
System.out.println("Enter the team name and their location as below: Ex. Australia Australia The maximum number of teams can be 10");
int i=0;
String inputTeam ="";
team[] teams = new team[10];
while (i<10)
{
inputTeam = input.nextLine();
teams[i] = new team(inputTeam.split(" ")[0],inputTeam.split(" ")[1]);
i++;
}
int numberGroupsReq = teams.length/4;
for (int g=0; g<= numberGroupsReq; g++)
{
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.