Vous êtes sur la page 1sur 4

CSC 2310: Assignment 4 (Spring 2012)

Due on Mar. 15 2012 2:30pm

Program #1:
The following is part of the source codes for the NFLTeam5 and NFLGameDay5 classes. Finish the programs for both classes to produce an output screen similar to the following figure. Note: when we test your program, we will enter different numbers and different names for the players.

//File NFLGameDay5.java 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); } //Construct Team Steelers //Simulate a game falcons.lossAgame(steelers); System.out.println (falcons); System.out.println (steelers); }//end of Main method }//end of class definition

// File NFLTeam5.java 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 int getTotalPlayersNum (){ return nTotalNumPlayers; } 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

What to turn in: 1. A directory named "HW4", consisting of all of the .java and the .class files. 2. A print out of each of the .java file (source code) and screenshots for compiling/running of the programs (if no print out is turned in, you will lose 20% of what the program is worth).

Note: 1. For all assignments, always use comments to include the programmer information, date, title of the program and brief description of the program. 2. No copying allowed. If it is found that students copy from each other, all of these programs will get 0. 3. You must use the name given to name your program. Should you use a different name, you would lose 10% of what the program is worth. 4. Make sure that your name is written clearly on the printout. 5. Make sure that both the .java and .class files are on the directory "HW4". If the jpb package is used in the program. Be sure to include the jpb package in the directory "HW4". Should you use any other subdirectory (whatsoever) your program would not be graded and you will receive a 0 (zero).

Vous aimerez peut-être aussi