Printing from an array

Trying to print from an array

Page 1 of 1

1 Replies - 638 Views - Last Post: 25 October 2010 - 09:47 PM Rate Topic: -----

#1 Guest_Pandamonium*


Reputation:

Printing from an array

Posted 25 October 2010 - 09:43 PM

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:

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.

Is This A Good Question/Topic? 0

Replies To: Printing from an array

#2 Guest_Pandamonium*


Reputation:

Re: Printing from an array

Posted 25 October 2010 - 09:47 PM

Somehow I managed to double post, Sorry.
Was This Post Helpful? 0

Page 1 of 1