Question: I previous submitted this question but i gunked it up. Opening another . import java.util.Random; public class Playoff { public static void main(String[] args) {
I previous submitted this question but i gunked it up. Opening another .
import java.util.Random;
public class Playoff {
public static void main(String[] args) {
int percent = 50;
Random rand = new Random();
tournament(percent, rand);
}
public static boolean singleGame(int percent, Random rand){
boolean outcome = false;
int generatedNumber = rand.nextInt(100);
if (generatedNumber >= percent) {
return true; }
else {
return outcome;
}
}
public static boolean playoff(int percent, Random rand) {
boolean outcome = false;
int wins1 = 0;// number of wins for wins1
int wins2 = 0;
boolean winner = false; //true if wins1 wins, otherwise false
while(true) { winner = singleGame(percent, rand);
if (winner) wins1 = wins1 + 1;
else wins2 = wins2 + 1;
if (wins1 == 4) { outcome = true;
break;
} //loop
else if(wins2 == 4) { outcome = false;
break;
}
}
return outcome;
}
public static void tournament(int percent, Random rand){
int wins1 = 0; // number of wins for wins1
int wins2 = 0; // number of wins for wins2
while (wins1 < wins2 + 10 && wins2 < wins1 + 10){
if (playoff(percent, rand)){ wins1++;
System.out.print(1);}
else{ wins2++;
System.out.print(2);}
}
System.out.println();
System.out.println();
System.out.println("Games wins 1 won: " + wins1);
System.out.println("Games wins 2 won: " + wins2);
System.out.println();
if (wins1 > wins2)
System.out.println("Team 1 has won the Tournament!");
else
System.out.println("Team 2 has won the Tournament!");
}
}
This the output which is what is desired:
2222212222111122212122211122122122
Games wins 1 won: 12
Games wins 2 won: 22
Team 2 has won the Tournament!
I was asked to rewrite the "tournament " method to include the following actions:
*** Check if the Math.abs(wins1 - wins2) is equal to 10
*** Then use the break statement to exit loop
This is where i am lost. Thank you .
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
