Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is my Code. Like the prompt said I just need help changing those 2 methods

ID: 3797559 • Letter: H

Question

Here is my Code. Like the prompt said I just need help changing those 2 methods that were mentioned. Thank you for your help!!!

public class League

{

private String name;

private int teamCount;

private Team[] teams;

private int [] [] gamesPlayed = new int[8][8];

public String getName() { return(name); }

public Team[] getTeams() { return(teams); }

public void setName(String aName) { name = aName; }

public League(String aName) {

name = aName;

teamCount = 0;

teams = new Team[8]; //This does not actually make any Team objects

}

//This is the toString method that specifies the appearance of the League

public String toString() {

return("The " + name + " league with " + teamCount + " teams.");

}

//This method adds a new team to the league

public int addTeam(Team aTeam) {

if (teamCount < 8) {

teams[teamCount++] = aTeam;

return teamCount;

}

return -1;

}

//This method prints out all of the teams

public void showTeams() {

for(int i=0; i<teamCount; i++)

System.out.println(teams[i].toString());

}

/****************** For LeagueTester1 *******************************/

//Record Win and Loss

public void recordWinAndLoss(Team winner, Team loser)

{  

  

   winner.setWins(winner.getWins() + 1);

   loser.setLosses(loser.getLosses() + 1);

  

  

}

//Record a Tie game

public void recordTie(Team teamA, Team teamB)

{

  

teamA.setTies(teamA.getTies() + 1);

teamB.setTies(teamB.getTies() + 1);

}

//Find the team with the given name. If none exists, return null

public Team teamWithName(String aName) {

for(int i=0; i<teamCount; i++) {

if (teams[i].getName().equals(aName))

return teams[i];

}

return null;

}

//Record Win and Loss

public void recordWinAndLoss(String winner, String loser) {

Team winningTeam, losingTeam;

if ((winningTeam = this.teamWithName(winner)) == null) {

System.out.println("Invalid Team name: " + winner);

return;

}

if ((losingTeam = this.teamWithName(loser)) == null) {

System.out.println("Invalid Team name: " + loser);

return;

}

recordWinAndLoss(winningTeam, losingTeam);

}

//Record a Tie game

public void recordTie(String teamAName, String teamBName) {

Team teamA, teamB;

if ((teamA = this.teamWithName(teamAName)) == null) {

System.out.println("Invalid Team name: " + teamAName);

return;

}

if ((teamB = this.teamWithName(teamBName)) == null) {

System.out.println("Invalid Team name: " + teamBName);

return;

}

recordTie(teamA, teamB);

}

//Return the total number of games played in the League

public int totalGamesPlayed() {

int total=0;

for (int i=0; i<teamCount; i++)

total += teams[i].gamesPlayed();

return total/2;

}

//Return the team with the most points

public Team firstPlaceTeam() {

Team best;

if (teamCount == 0)

return null;//If there are no teams, then no team is in first place

best = teams[0];

for (int i=1; i<teamCount; i++) {

if (best.totalPoints() < teams[i].totalPoints())

   best = teams[i];

}

return best;

}

//Return the team with the least points

public Team lastPlaceTeam() {

Team worst;

if (teamCount == 0)

return null;//If there are no teams, then no team is in last place

worst = teams[0];

for (int i=1; i<teamCount; i++) {

if (worst.totalPoints() > teams[i].totalPoints())

worst = teams[i];

}

return worst;

}

//Returns the team who played the most

public Team teamMostPlayed()

{

Team most;

if (teamCount == 0)

return null;

most = teams[0];

for (int i=1; i<teamCount; i++) {

if (most.gamesPlayed() < teams[i].gamesPlayed())

   most = teams[i];

}

return most;

}

//Returns undefeated teams

public Team[] undefeated()

{

   int count= 0;

   for(int i = 0; i < teams.length; i++)

   {

       if(teams[i].getLosses() == 0)

       {

           count = count + 1;

       }

   }

   Team[] undefeated = new Team[count];

   count = 0;

   for(int i = 0; i < teams.length; i++)

   {

       if(teams[i].getLosses() == 0)

       {

           undefeated[count] = teams[i];

           count = count + 1;

       }

   }

   return undefeated;

}

//returns index of specific team of a league

public int indexOf(Team t)

{

   for(int i=0; i<teams.length; i++)

{

       if(teams[i] == t)

           return i;

}

           return -1;

}

//This method prints out a table showing which teams played which other teams

public void showTable()

{

System.out.println(" 0 1 2 3 4 5 6 7 ");

System.out.println(" -------------------------------");

for(int row=0; row<8; row++)

    {

System.out.print(row +" | ");

for(int col=0; col<8; col++)

{

System.out.print(gamesPlayed[row][col] + " | ");

}

System.out.println(" -------------------------------");

}

for(int i=0; i<8; i++)

System.out.println(i + " = " + teams[i].getName());

}

}

0 1 2 3 4 5 6 7 0 l 0 l 010 0 0 l 0 0 l 0 1 l 0 0 010 0 0 l 0 0 l 2 l 0 0 l 010 0 l 010 l 3 l 010 l 010 010 l 010 l 4 l 010 l 010 010 l 010 l 5 0 0 0 0 0 0 0 0 6 l 0 l 0 0 l l 0 l 0 0 l 0 0 7 l 010 l 010 010 l 0| 0 l 0 Chicago Bulls Detroit Pistons 1 2- New Jersey Nets 3 Toronto Raptors 4 New York Knicks Atlanta Hawks 6 Boston Celtics Indiana Pacer

Explanation / Answer

public class League
{
private String name;
private int teamCount;
private Team[] teams;
private int[][] gamesPlayed = new int[8][8];


public String getName() { return(name); }
public Team[] getTeams() { return(teams); }
public void setName(String aName) { name = aName; }

public League(String aName) {
name = aName;
teamCount = 0;
teams = new Team[8]; //This does not actually make any Team objects
}

//This is the toString method that specifies the appearance of the League
public String toString() {
return("The " + name + " league with " + teamCount + " teams.");
}


//This method adds a new team to the league
public int addTeam(Team aTeam) {
if (teamCount < 8) {
teams[teamCount++] = aTeam;
return teamCount;
}
return -1;
}

//This method prints out all of the teams
public void showTeams() {
for(int i=0; i<teamCount; i++)
System.out.println(teams[i].toString());
}


/****************** For LeagueTester1 *******************************/

//Record Win and Loss
public void recordWinAndLoss(Team winner, Team loser)
{
  
winner.setWins(winner.getWins() + 1);
loser.setLosses(loser.getLosses() + 1);
int x = indexOf(winner);
int y = indexOf(loser);
gamesPlayed[x][y] + = 1;
gamesPlayed[y][x] + = 1;

  
}
//Record a Tie game
public void recordTie(Team teamA, Team teamB)
{
  
teamA.setTies(teamA.getTies() + 1);
teamB.setTies(teamB.getTies() + 1);
int x = indexOf(teamA);
int y = indexOf(teamB);
gamesPlayed[x][y] + = 1;
gamesPlayed[y][x] + = 1;

}



//Find the team with the given name. If none exists, return null
public Team teamWithName(String aName) {
for(int i=0; i<teamCount; i++) {
if (teams[i].getName().equals(aName))
return teams[i];
}
return null;
}


//Record Win and Loss
public void recordWinAndLoss(String winner, String loser) {
Team winningTeam, losingTeam;
if ((winningTeam = this.teamWithName(winner)) == null) {
System.out.println("Invalid Team name: " + winner);
return;
}
if ((losingTeam = this.teamWithName(loser)) == null) {
System.out.println("Invalid Team name: " + loser);
return;
}
recordWinAndLoss(winningTeam, losingTeam);
}

//Record a Tie game
public void recordTie(String teamAName, String teamBName) {
Team teamA, teamB;

if ((teamA = this.teamWithName(teamAName)) == null) {
System.out.println("Invalid Team name: " + teamAName);
return;
}
if ((teamB = this.teamWithName(teamBName)) == null) {
System.out.println("Invalid Team name: " + teamBName);
return;
}
recordTie(teamA, teamB);
}


//Return the total number of games played in the League
public int totalGamesPlayed() {
int total=0;
for (int i=0; i<teamCount; i++)
total += teams[i].gamesPlayed();
return total/2;
}
//Return the team with the most points
public Team firstPlaceTeam() {
Team best;
if (teamCount == 0)
return null;//If there are no teams, then no team is in first place
best = teams[0];
for (int i=1; i<teamCount; i++) {
if (best.totalPoints() < teams[i].totalPoints())
best = teams[i];
}
return best;
}

//Return the team with the least points
public Team lastPlaceTeam() {
Team worst;
if (teamCount == 0)
return null;//If there are no teams, then no team is in last place
worst = teams[0];
for (int i=1; i<teamCount; i++) {
if (worst.totalPoints() > teams[i].totalPoints())
worst = teams[i];
}
return worst;
}
//Returns the team who played the most
public Team teamMostPlayed()
{
Team most;
if (teamCount == 0)
return null;
most = teams[0];
for (int i=1; i<teamCount; i++) {
if (most.gamesPlayed() < teams[i].gamesPlayed())
most = teams[i];
}
return most;
}
//Returns undefeated teams
public Team[] undefeated()
{
int count= 0;
for(int i = 0; i < teams.length; i++)
{
if(teams[i].getLosses() == 0)
{
count = count + 1;
}
}
Team[] undefeated = new Team[count];
count = 0;
for(int i = 0; i < teams.length; i++)
{
if(teams[i].getLosses() == 0)
{
undefeated[count] = teams[i];
count = count + 1;
}

}

return undefeated;

}
//returns index of specific team of a league
public int indexOf(Team t)
{
for(int i=0; i<teams.length; i++)
{
if(teams[i] == t)
return i;
}
return -1;
}
//This method prints out a table showing which teams played which other teams
public void showTable()
{
System.out.println(" 0 1 2 3 4 5 6 7 ");
System.out.println(" -------------------------------");
for(int row=0; row<8; row++)
{
System.out.print(row +" | ");
for(int col=0; col<8; col++)
{
System.out.print(gamesPlayed[row][col] + " | ");
}
System.out.println(" -------------------------------");
}
for(int i=0; i<8; i++)
System.out.println(i + " = " + teams[i].getName());
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote