import jpb.*;
public class NFLGameDay5 {
public static void main(String[] args) {
//Construct Team Falcons
NFLTeam5 falcons = new NFLTeam5("Falcons");
SimpleIO.prompt("How many players do the 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 do the Steelers own:");
userInput = SimpleIO.readLine().trim();
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);
//steelers.deleteAPlayer(userInput);
}
//Simulate a game
falcons.lossAgame(steelers);
System.out.println(falcons);
System.out.println(steelers);
}//end of Main method
}//end of class definition
and here is the other part
// File NFLTeam5.java
public class NFLTeam5{
private String[] sPlayerArray;
private int nTotalNumPlayers;
private int win;
private int loss;
private String TeamName;
int TotalNum;
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 int getTotalPlayersNum (){
return nTotalNumPlayers;
}
public void addAPlayer (String playerA)
{
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";
for (int i =0; i< nTotalNumPlayers; i++)
sOutput = sOutput + sPlayerArray[i] + "\n";
return sOutput;
}
}//end of class definition
Currently this is what prints out:
How many players do the Falcons own: 1
Enter the name of Player #1: d
How many Players do the Steelers own:1
Enter the name of Player #1: d
Falcons Win/Loss: 0 / 1 games
Number of Players is: 0
Steelers Win/Loss: 1 / 0 games
Number of Players is: 0
I cant get the players to print out. Any help would be much appreciated, I am sure that I its something really stupid that messing up.
Thanks.

New Topic/Question
Reply
MultiQuote

|