3.1. Coach class
For this class you only need to implement two constructors; the overloaded and copy constructor
in addition to the static factory methods.
3.2. Player class
Two types of the constructors (overloaded and copy) and all the setter and getter methods is what
you need to implement for this task. Also, you should implement the static factory methods.
3.3. Soccer Team class
Three types of the constructors (default, overloaded and copy) and all the setter and getter
methods plus the static factory methods is what you need to implement for this task.
Please note that the instance variables in this class are all private, as the UML shows.
/**
* This class implements a simple soccer team
*@author May Haidar
*/
public class SoccerTeam {
/**
* This is the default constructors.
* At most 11 player can play this team.
* At most there are 4 roles players can have.
*/
private SoccerTeam() {
}
/**
* This is the overloaded constructor for this class
* @param player is an array containing all the players who entered the team.
* @param coach is the area that is available to the players to play.
*/
private SoccerTeam (Player [] player, Coach coach) {
}
/**
* This the copy constructor for this class
* @param team is an object of SoccerTeam, whose component is deeply copied into
* the component of this object.
*/
private SoccerTeam (SoccerTeam team) {
}
/**
* This is a static factory method
* @return IT returns an object of SoccerTeam
*/
public static SoccerTeam getInstance() {
}
/**
* This is a static factory method
* @param player is an array that contains players.
* @param coach is a coach of the team
* @return It returns an object of SoccerTeam made using the input parameters.
*/
public static SoccerTeam getInstance(Player [] player, Coach coach) {
}
/**
* This is a static factory method
* @param team is an object of SoccerTeam
* @return it returns an object of SoccerTeam made using the input parameter.
*/
public static SoccerTeam getInstance(SoccerTeam team) {
}
/**
* This is the getter method for the player list.
* @return returns an array containing all the players of this team.
*/
public Player[] getPlayers() {
}
/**
* This is the getter method for the coach attribute.
* @return Returns an object of coach containing all the components of this team's coach.
*/
public Coach getCoach() {
}
/**
* This is the setter method for the player attribute, which deeply copies
* the input parameter into the player attribute of this object.
* @param player is an array of Player, whose elements are copied in the player attribute of this
object.
*/
public void setPlayers(Player [] player) {
}
/**
* This is the setter method for the coach attribute, which deeply copies
* the input parameter into the coach attribute of this object.
* @param coach is an object of Coach, whose attributes are copied in the coach attribute of this
object.
*/
public void setCoach(Coach coach) {
}
}
/**
*
* This class implements all a player requires to play in this team.
* A player.
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
31 Coach class For this class you only need to implement .pdf
1. 3.1. Coach class
For this class you only need to implement two constructors; the overloaded and copy constructor
in addition to the static factory methods.
3.2. Player class
Two types of the constructors (overloaded and copy) and all the setter and getter methods is what
you need to implement for this task. Also, you should implement the static factory methods.
3.3. Soccer Team class
Three types of the constructors (default, overloaded and copy) and all the setter and getter
methods plus the static factory methods is what you need to implement for this task.
Please note that the instance variables in this class are all private, as the UML shows.
/**
* This class implements a simple soccer team
*@author May Haidar
*/
public class SoccerTeam {
/**
* This is the default constructors.
* At most 11 player can play this team.
* At most there are 4 roles players can have.
*/
private SoccerTeam() {
}
/**
* This is the overloaded constructor for this class
* @param player is an array containing all the players who entered the team.
* @param coach is the area that is available to the players to play.
*/
private SoccerTeam (Player [] player, Coach coach) {
}
/**
* This the copy constructor for this class
* @param team is an object of SoccerTeam, whose component is deeply copied into
* the component of this object.
*/
private SoccerTeam (SoccerTeam team) {
}
2. /**
* This is a static factory method
* @return IT returns an object of SoccerTeam
*/
public static SoccerTeam getInstance() {
}
/**
* This is a static factory method
* @param player is an array that contains players.
* @param coach is a coach of the team
* @return It returns an object of SoccerTeam made using the input parameters.
*/
public static SoccerTeam getInstance(Player [] player, Coach coach) {
}
/**
* This is a static factory method
* @param team is an object of SoccerTeam
* @return it returns an object of SoccerTeam made using the input parameter.
*/
public static SoccerTeam getInstance(SoccerTeam team) {
}
/**
* This is the getter method for the player list.
* @return returns an array containing all the players of this team.
*/
public Player[] getPlayers() {
}
/**
* This is the getter method for the coach attribute.
* @return Returns an object of coach containing all the components of this team's coach.
*/
public Coach getCoach() {
}
/**
3. * This is the setter method for the player attribute, which deeply copies
* the input parameter into the player attribute of this object.
* @param player is an array of Player, whose elements are copied in the player attribute of this
object.
*/
public void setPlayers(Player [] player) {
}
/**
* This is the setter method for the coach attribute, which deeply copies
* the input parameter into the coach attribute of this object.
* @param coach is an object of Coach, whose attributes are copied in the coach attribute of this
object.
*/
public void setCoach(Coach coach) {
}
}
/**
*
* This class implements all a player requires to play in this team.
* A player has a number, a name, and a role. A role can be either defense, central, striker, or goal
keeper.
* these roles can be represented by the characters 'd', 'c', 's', or 'g'
*
*/
class Player {
/**
* This is the overloaded constructor for this class
* @param name
* @param role
*/
private Player(int num, String name, char role) {
}
/**
* This is the copy constructor for this class
* @param player
*/
private Player(Player player) {
4. }
/**
* This is a static factory method.
* @return It returns an object of Player
*/
public static Player getInstance() {
}
/**
* This is a static factory method
* @param name is the name of player
* @param role is the role of the player in the team
* @return It returns an object of player, which is made by the two input variables.
*/
public static Player getInstance(int num, String name, char role) {
}
/**
* This is a static factory method
* @param player is an object of player
* @return it returns an object of player that is made using the input parameter.
*/
public static Player getInstance(Player player) {
}
/**
* This is the getter method for attribute name
* @return returns the value of attribute name
*/
public String getName() {
}
/**
* This is the getter method for attribute role
* @return returns the reference to attribute role.
*/
public char getRole() {
}
/**
5. * This is the setter method for attribute name
* @param name is the value that is used to initialize name attribute
*/
public void setName(String name) {
}
/**
* This is the setter method for attribute role
* @param role is the object, whose reference is used to initialize attribute role.
*/
public void setRole(char role) {
}
}
/**
* This class represents the coach who coaches the team.
*
*/
class Coach{
/**
* This is the overloaded constructor.
* @param name is the first area in which player can play.
* @param yearsExp is the second area in which player can play.
* @param level is the third area in which player can play.
* @param airShip is the fourth area in which player can play.
*/
private Coach(String name, int yearsExp, String level) {
}
/**
* This is a static factory method that initializes the attributes to their default values.
* @return It returns an object of MAP
*/
public static Coach getInstance() {
}
/**
* This is a static factory method
6. * @param name is the first area in which player can play.
* @param yearsExp is the second area in which player can play.
* @param level is the third area in which player can play.
* @param airShip is the fourth area in which player can play.
* @return it returns an object of MAP.
*/
public static Coach getInstance(String name, int yearsExp, String level) {
}
/**
* This is the copy constructor.
* @param coach is an object of Coach that is used to initialize this object.
*/
private Coach(Coach coach) {
}
public static Coach getInstance(Coach coach) {
}
}
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class SoccerTeamTest {
@Test
void testCoach1() {
Coach coach = Coach.getInstance();
boolean expected = true;
boolean actual = (coach.name.compareTo("") == 0) && (coach.yearsExp == 0)
&& (coach.level.compareTo("") == 0);
assertEquals(actual, expected, "The coach is not initialized correctly by the default constructor of
the Coach class.");
}
@Test
void testCoach2() {
Coach coach = Coach.getInstance("Xavi", 20, "high");
boolean expected = true;
boolean actual = (coach.name.compareTo("Xavi") == 0) && (coach.yearsExp == 20) &&
(coach.level.compareTo("high") == 0);
assertEquals(actual, expected, "The coach is not initialized correctly by the overloaded constructor
7. of the Coach class.");
}
@Test
void testCoach3() {
Coach coach1 = Coach.getInstance("Benni", 10, "beginner");
Coach coach2 = Coach.getInstance(coach1);
boolean expected = true;
boolean actual = (coach1.name.compareTo(coach2.name) == 0) && (coach1.yearsExp ==
coach2.yearsExp) &&
(coach1.level.compareTo(coach2.level) == 0);
assertEquals(actual, expected, "The coach is not initialized correctly by the copy constructor of the
Coach class.");
}
@Test
void testPlayer1() {
Player player = Player.getInstance(1, "Messi", 's');
char role ='s';
boolean expected = true;
boolean actual = (role == player.getRole());
assertEquals(actual, expected, "The aggregation relationship is not correcly implemented for the
Player class [wrong getter method].");
}
@Test
void testPlayer2() {
char role = 'g';
Player player = Player.getInstance();
player.setRole(role);
boolean expected = true;
boolean actual = (role == player.role);
assertEquals(actual, expected, "The aggregation relationship is not correcly implemented for the
Player class.[wrong setter method]");
}
@Test
void testPlayer3() {
char role = 'd';
Player player1 = Player.getInstance(2, "Ronaldo", role);
Player player2 = Player.getInstance(player1);
boolean expected = true;
boolean actual = (player1.getRole() == player2.getRole()) && (player2.getRole() == role);
assertEquals(actual, expected, "The aggregation relationship is not correcly implemented in the
copy constructor, for role attribute in Player class.");
}
8. @Test
void testPlayer4() {
char role = 'c';
Player player1 = Player.getInstance(3, "Benzema", role);
Player player2 = Player.getInstance(3, "Benzema", role);
boolean expected = true;
boolean actual = (player1.getName() == player2.getName());
assertEquals(actual, expected, "The aggregation relationship is not correctly implemented for
name in Player class.");
}
@Test
void testPlayer5() {
char role = 'g';
Player player1 = Player.getInstance(10, new String("Casillas"), role);
Player player2 = Player.getInstance(10, "Casillas", role);
boolean expected = true;
boolean actual = (player1.getName() != player2.getName());
assertEquals(actual, expected, "The aggregation relationship is not correctly implemented for
name in Player class.");
}
@Test
void testSoccerTeam1() {
Player player1 = Player.getInstance(1, "Messi", 's');
Player player2 = Player.getInstance(2, "Neymar", 'd');
Player [] players = new Player[2];
players[0] = player1;
players[1] = player2;
Coach coach = Coach.getInstance();
SoccerTeam team = SoccerTeam.getInstance(players, coach);
boolean expected = true;
boolean actual = (team.getPlayers() != players);
assertEquals(actual, expected, "The Composition relationship is not correctly implemented for the
player list in SoccerTeam class [getPlayer].");
}
@Test
void testSoccerTeam2() {
Player player1 = Player.getInstance(1, "Messi", 's');
Player player2 = Player.getInstance(2, "Neymar", 'd');
Player [] players = new Player[2];
players[0] = player1;
9. players[1] = player2;
Coach coach = Coach.getInstance("Xavi", 20, "high");
SoccerTeam team = SoccerTeam.getInstance(players, coach);
boolean expected = true;
boolean actual = (team.getCoach() != coach);
assertEquals(actual, expected, "The Composition relationship is not correctly implemented for the
coach attribute in SoccerTeam class [getCoach].");
}
@Test
void testSoccerTeam3() {
Player player1 = Player.getInstance(1, "Messi", 's');
Player player2 = Player.getInstance(2, "Neymar", 'd');
Player [] players = new Player[2];
players[0] = player1;
players[1] = player2;
Coach coach = Coach.getInstance("Xavi", 20, "high");
SoccerTeam team = SoccerTeam.getInstance();
team.setCoach(coach);
team.setPlayers(players);
boolean expected = true;
boolean actual = (team.getCoach() != coach) && (team.getPlayers() != players);
assertEquals(actual, expected, "The Composition relationship is not correctly implemented for
coach in SoccerTeam class [setCoach and setPlayer].");
}
@Test
void testSoccerTeam4() {
Player player1 = Player.getInstance(1, "Messi", 's');
Player player2 = Player.getInstance(2, "Neymar", 'd');
Player [] players = new Player[2];
players[0] = player1;
players[1] = player2;
Coach coach = Coach.getInstance("Xavi", 20, "high");
SoccerTeam team = SoccerTeam.getInstance();
team.setCoach(coach);
team.setPlayers(players);
boolean expected = true;
boolean actual = (team.getCoach().level != coach.level);
assertEquals(actual, expected, "The Composition relationship is not correctly implemented for
coach in SoccerTeam class [setCoach].");
10. }
@Test
void testSoccerTeam5() {
Player player1 = Player.getInstance(1, "Messi", 's');
Player player2 = Player.getInstance(2, "Neymar", 'd');
Player [] players = new Player[2];
players[0] = player1;
players[1] = player2;
Coach coach = Coach.getInstance("Xavi", 20, "high");
SoccerTeam team = SoccerTeam.getInstance();
team.setCoach(coach);
team.setPlayers(players);
boolean expected = true;
boolean actual = (team.getPlayers()[0].name != players[0].name);
assertEquals(actual, expected, "The Composition relationship is not correctly implemented for
coach in SoccerTeam class [setPlayer].");
}
@Test
void testSoccerTeam6() {
Player player1 = Player.getInstance(1, "Messi", 's');
Player player2 = Player.getInstance(2, "Neymar", 'd');
Player [] players = new Player[2];
players[0] = player1;
players[1] = player2;
Coach coach = Coach.getInstance("Xavi", 20, "high");
SoccerTeam team1 = SoccerTeam.getInstance(players, coach);
SoccerTeam team2 = SoccerTeam.getInstance(players, coach);
boolean expected = true;
boolean actual = (team1.getPlayers() != team2.getPlayers());
assertEquals(actual, expected, "The Composition relationship is not correctly implemented for
player array in SoccerTeam class [copy constructor or overloaded constructor].");
}
@Test
void testSoccerTeam7() {
Player player1 = Player.getInstance(1, "Messi", 's');
Player player2 = Player.getInstance(2, "Neymar", 'd');
Player [] players = new Player[2];
players[0] = player1;
players[1] = player2;
Coach coach = Coach.getInstance("Xavi", 20, "high");
11. SoccerTeam team1 = SoccerTeam.getInstance(players, coach);
SoccerTeam team2 = SoccerTeam.getInstance(players, coach);
boolean expected = true;
boolean actual = (team1.getCoach() != team2.getCoach());
assertEquals(actual, expected, "The Composition relationship is not correctly implemented for
coach in SoccerTeam class [copy constructor or overloaded constructor].");
}
}