Hello, I need help on the NFLTeam program that uses an array on the number of players and their names. I've been doing an NFLTeam program where it prints the wins and losses of both falcons and steelers as well as printing out the number of players in those teams including their names. This is the program that I have so far:
NFLTeam5
public class NFLTeam5
{
private String[] sPlayerArray;
private int nTotalNumPlayers;
private int win;
private int loss;
private String TeamName;
public NFLTeam5(String eName)
{
win=0;
loss=0;
TeamName = eName;
nTotalNumPlayers=0;
}
public void winAgame()
{
win++;
}
public void winAgame(NFLTeam5 teamB)
{
win++;
teamB.lossAgame();
}
public void lossAgame()
{
loss++;
}
public void lossAgame(NFLTeam5 teamB)
{
loss++;
teamB.winAgame();
}
public int getWinNum()
{
return win;
}
public int getLossNum()
{
return loss;
}
public String getName()
{
return TeamName;
}
public String[] getPlayerName()
{
return sPlayerArray;
}
public int getTotalPlayersNum ()
{
return nTotalNumPlayers;
}
public void addAPlayer (String playerA)
{
// nTotalNumPlayers++;
String [] sPlayerArrayTemp=new String [nTotalNumPlayers];
for (int i =0,j=0; i< nTotalNumPlayers; i++,j++)
{
if (sPlayerArray[j]!=playerA)
sPlayerArrayTemp[i]=sPlayerArray[j];
else
sPlayerArrayTemp[i]=sPlayerArray[++j];
}
sPlayerArray=sPlayerArrayTemp;
}
public void deleteAPlayer (String playerA)
{
nTotalNumPlayers--;
String [] sPlayerArrayTemp=new String [nTotalNumPlayers];
for (int i =0,j=0; i< nTotalNumPlayers; i++,j++)
{
if (sPlayerArray[j]!=playerA)
sPlayerArrayTemp[i]=sPlayerArray[j];
else
sPlayerArrayTemp[i]=sPlayerArray[++j];
}
sPlayerArray=sPlayerArrayTemp;
}
public String toString()
{
String sOutput=TeamName + " Win/Loss: " + win + " / "+ loss + " games ";
sOutput = sOutput+ "\n" + "Number of Players is: " + nTotalNumPlayers + "\n";
//sOutput = sOutput + "\n" + getPlayerName;
for (int i =0; i< nTotalNumPlayers; i++)
sOutput = sOutput + sPlayerArray[i] + "\n";
return sOutput;
}
}//end of class definition
NFLTeamGameDay5
import jpb.*;
public class NFLGameDay5
{
public static void main (String [] args)
{
//Construct Team Falcons
NFLTeam5 falcons = new NFLTeam5("Falcons");
SimpleIO.prompt("How many players Falcons own: ");
String userInput = SimpleIO.readLine().trim();
int numberOfPlayers = Integer.parseInt(userInput);
// Prompt user to enter players into the Team
for (int i = 0; i < numberOfPlayers; i++)
{
SimpleIO.prompt("Enter the name of Player #" + (i + 1) + ": ");
userInput = SimpleIO.readLine().trim();
falcons.addAPlayer(userInput);
//falcons.deleteAPlayer(userInput);
}
//Construct Team Steelers
NFLTeam5 steelers = new NFLTeam5("Steelers");
SimpleIO.prompt("How many players Steelers own: ");
userInput = SimpleIO.readLine().trim();
int numberOfPlayers2 = Integer.parseInt(userInput);
// Prompt user to enter players into the Team
for (int i = 0; i < numberOfPlayers2; i++)
{
SimpleIO.prompt("Enter the name of Player #" + (i + 1) + ": ");
userInput = SimpleIO.readLine().trim();
steelers.addAPlayer(userInput);
}
//Simulate a game
falcons.lossAgame(steelers);
System.out.println (falcons);
System.out.println (steelers);
}//end of Main method
}//end of class definition
So far, I've got the output for the wins and losses, but it's not printing out the players names and the number of players is always at 0. Am I forgetting something in there? Please reply back. Thanks.