Question: public class Team { private String teamName; private static int teamId=999; private int numberOfPlayers; private String captain; private int tID; public Team() { teamId++; tID=teamId;

public class Team { private String teamName; private static int teamId=999; private int numberOfPlayers; private String captain; private int tID; public Team() { teamId++; tID=teamId; } public Team(String name,int noOfPlayers,String capName){ if(!name.equalsIgnoreCase(null) && !name.equalsIgnoreCase("") && noOfPlayers!=0){ this.setTeamName(name); this.setNumberOfPlayers(noOfPlayers); captain=capName; teamId++; tID=teamId; } else{ throw new IllegalArgumentException("Team name can not be null and players can not be 0"); } } public String getTeamName() { return teamName; } public void setTeamName(String teamName) { if(!teamName.isEmpty() && teamName!="") this.teamName = teamName; else this.teamName=null; } public static int getTeamId() { return teamId; } public int getNumberOfPlayers() { return numberOfPlayers; } public void setNumberOfPlayers(int numberOfPlayers) { if(numberOfPlayers>=7 && numberOfPlayers<=13){ this.numberOfPlayers = numberOfPlayers; } } public String getCaptain() { return captain; } public void setCaptain(String captain) { this.captain = captain; } public String getTeamInfo(){ return "Team ID: "+this.tID+", Team Name : "+this.teamName+", # of Team Members :"+this.numberOfPlayers+",Captain "+this.captain; } public String toString(){ return "team name"+this.teamName+"no of players"+this.numberOfPlayers; } } import java.util.ArrayList; import java.util.List; public class LeagueTester { public static void main(String[] args) { List listOfTeam=new ArrayList<>();

Team T1=new Team("Lakers",10,"robert");

Team T2=new Team("BKAERS",11,"lewis");

Team T3=new Team("Vipers",8,"Podrick");

Team T4=new Team("zeus",7,"john");

Team T5=new Team("Zar",7,"kobe");

listOfTeam.add(T1); listOfTeam.add(T2); listOfTeam.add(T3); listOfTeam.add(T4); listOfTeam.add(T5); for(Team t:listOfTeam){ System.out.println(t.getTeamInfo()); } } }

Modify the League project. Add a new method called createSameTeamForNextSession( ) to the Team class to duplicate team details, but include a new teamId. This method should return a team and use all the same team details as the team it is based off of, but it will receive a new teamId (the next one available from the static variable). The constructor in the method might look a little funky but this is how you can get the data out of the object you are using:

Team t = new Team(this.teamName, this.numberOfPlayers, this.captain);

This method should not take a parameter.

In your tester, create three new teams based off existing teams. Print them out to verify they are getting new teamIDs for each time they are created. As a reminder, your method will be returning a team, so you will need to capture it in your tester. Then add it to your arraylist or just print it out using your special formatted method (not the toString( )).

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 Databases Questions!