Question: Does the attached code answer this question? Complete the code for the Player and Team classes. Each class must derive from the Entity class, as

Does the attached code answer this question?
Complete the code for the Player and Team classes. Each class must derive from the Entity class, as demonstrated in the UML diagram.
Every team and player must have a unique name by searching for the supplied name prior to adding the new instance. Use the iterator pattern in the addTeam() and addPlayer() methods.
public class Entity {
private long id;
private String name;
public Entity(){
}
public Entity(long id, String name){
this.id = id;
this.name = name;
}
public long getId(){
return id;
}
public String getName(){
return name;
}
@Override
public String toString(){
return "Entity [id="+ id +", name="+ name +"]";
}
}
public class Player extends Entity {
long id;
String name;
/*
Constructor with an identifier and name
*/
public Player(long id, String name){
this.id = id;
this.name = name;
}
/**
@return the id
*/
public long getId(){
return id;
}
/**
@return the name
*/
public String getName(){
return name;
}
@Override
public String toString(){
return "Player [id="+ id +", name="+ name +"]";
}
}
public class Game extends Entity {
long id;
String name;
/**
Hide the default constructor to prevent creating empty instances.
*/
private Game(){
}
/**
Constructor with an identifier and name
*/
public Game(long id, String name){
this();
this.id = id;
this.name = name;
}
/**
@return the id
*/
public long getId(){
return id;
}
/**
@return the name
*/
public String getName(){
return name;
}
//Creates and returns a new team object
public Team addTeam(String name){
Team team = new Team(getId(), name);
return team;
}
@Override
public String toString(){
}
return "Game [id="+ id +", name="+ name +"]";
}
public class Team extends Entity {
long id;
String name;
/*
Constructor with an identifier and name
*/
public Team(long id, String name){
this.id = id;
this.name = name;
}
/**
@return the id
*/
public long getId(){
return id;
}
/**
@return the name
*/
public String getName(){
return name;
}
//method for the creation of a player object, returns the player
public Player addPlayer(String name){
Player player = new Player(getId(), name);
return player;
}
@Override
public String toString(){
return "Team [id="+ id +", name="+ name +"]";
}
}
Does the attached code answer this question?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!