import java.util.*;
import java.util.Random;
public class Playoffs
{
public static Scanner scan = new Scanner(System.in);
public static void main(String [] args)
{
boolean validNumber;
int game1;
System.out.print("What is the % chance that team 1 will win the game?");
do{
game1 = scan.nextInt();
validNumber = game1 >= 0 && game1 <=100;
if(!validNumber){
System.out.println("INVALID NUMBER ENTERED: NOT BETWEEN 0 AND 100");
System.out.print("Enter a valid number between 0 and 100: ");
}
}while(!validNumber);
System.out.println("Team 1 has a " + game1 + "% chance of winning.");
The code below should generate a random number between 0 (inclusive) and 100 (exclusive), stating that if the random number is less than the percentage the user input, team 1 will win, and team 2 should win if the random number is greater than the percentage entered, but it always comes out that team 1 wins
Random rand = new Random(100);
int randomNumber = rand.nextInt();
int oneGame = simulateOneGame(game1, randomNumber);
if(oneGame == 1){
System.out.println("\nTeam 1 has won the game");
}else if(oneGame == 0){
System.out.println("\nTeam 2 has won the game");
}
}
public static int simulateOneGame(int game1, int randomNumber)
{
int result=0;
if (randomNumber < game1) {
result += 1;
} else if(randomNumber > game1){
result += 0;
}
return result;
}
}