Created
January 6, 2016 01:17
-
-
Save billmote/164e3bac772b4dd2a170 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SoccerTeam { | |
private static int numWins; | |
private static int numLosses; | |
private static int numTies; | |
//these 2 variables are for the modified version | |
private static int numGames=0; | |
private static int numGoals=0; | |
private static final int POINTS_PER_WIN = 3; | |
private static final int POINTS_PER_TIE = 1; | |
public void played(SoccerTeam other, int myScore, int theirScore) { | |
if(myScore > theirScore) { | |
numWins++; | |
other.numLosses++; | |
}else if (myScore < theirScore) { | |
numLosses++; | |
other.numWins++; | |
}else { | |
numTies++; | |
other.numTies++; | |
} | |
//in the modified version you would also have to do | |
numGames++; | |
numGoals+=myScore + theirScore; | |
} | |
public static int getnumPoints() { | |
return POINTS_PER_WIN * numWins + POINTS_PER_TIE * numTies; | |
} | |
public void reset() { | |
numWins=0; | |
numLosses=0; | |
numTies=0; | |
} | |
public static int getNumGames() { | |
return numGames; | |
} | |
public static int getNumGoals() { | |
return numGoals; | |
} | |
public void startTournament() { | |
numGoals=0; | |
numGames=0; | |
} | |
public static void main(String [] args) { | |
SoccerTeam team1 = new SoccerTeam(); // Changed for readability | |
SoccerTeam team2 = new SoccerTeam(); | |
SoccerTeam team3 = new SoccerTeam(); | |
SoccerTeam team4 = new SoccerTeam(); | |
for(int i=0; i<2; i++) { | |
team1.played(team2, 4, 1); | |
team2.played(team3, 2, 4); | |
team3.played(team4, 1 , 0); | |
team4.played(team1, 1, 3); | |
int numPoints; | |
for(int game = 1; game <= 4; game++) { | |
switch(game) { | |
case 1: | |
numPoints = team1.getnumPoints(); | |
break; | |
case 2: | |
numPoints = team2.getnumPoints(); | |
break; | |
case 3: | |
numPoints = team3.getnumPoints(); | |
break; | |
case 4: | |
numPoints = team4.getnumPoints(); | |
break; | |
} | |
System.out.println("Team" + team + " has " + numPoints + " points"); // Changed from SoccerTeam.getNumPoints() | |
} | |
System.out.println(i * 4 + " were played and " + SoccerTeam.getNumGoals() + " were scored"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!