#Java
1 messages · Page 1 of 1 (latest)
Where are you stuck? As it stands we have your assignment.
public static void updateScore(int teamNumber, int points) {
switch (teamNumber) {
case 11: seliparWarriors += points; break;
case 21: slipStrike += points; break;
case 45: flipFlopFighters += points; break;
case 66: slipperSnipers += points; break;
case 7: throwLuckySeven += points; break;
case 34: seliparSlayers += points; break;
}
}
public static void displayScores() {
System.out.println("SeliparWarriors: " + seliparWarriors);
System.out.println("SlipStrike: " + slipStrike);
System.out.println("FlipFlopFighters: " + flipFlopFighters);
System.out.println("SlipperSnipers: " + slipperSnipers);
System.out.println("ThrowLuckySeven: " + throwLuckySeven);
System.out.println("SeliparSlayers: " + seliparSlayers);
}
Detected code, here are some useful tools:
System out
[Nothing]
This is the method for updateScore and displayScores
but how to determine the winner in another method determineWinner? write one by one if-else?
You'd use some kind of loop to dermine which team in the list has the highest number, you don't want to add another else whenever a new team gets added.
do you mean for loop
but if I want to execute for loop, then have to use array, am I right?
A basic for, a while, an enhanced for, a stream, etc..
And yes, I'd store the list of teams in a list.
Java
Closed the thread.