Hello, I am trying to construct a football simulator game, here is the code that I have so far:
My issue is when I run it, it prints "You have won the coin toss!" twice, no matter what the outcome is, could you explain to me what I am doing wrong?import java.util.Scanner; import java.util.Random; public class gamePlay{ public static int Downs = 0; public static int Yards = 0; public static String Coin = null; public static String Choice = null; public static String Toss = null; public static String heads; public static String tails; public static String Heads; public static String Tails; public static String Yes; public static String No; public static void main (String[]args){ Scanner keyboard = new Scanner(System.in); System.out.println("Welcome to todays game, it's time for the coin toss."); System.out.println("Please Pick Heads Or Tails By typing you answer."); String HT = keyboard.nextLine(); switch(HT) { case "Heads": case "heads": Choice = heads; //TODO Make Answer Random coinToss(); break; case "Tails": case "tails": Choice = tails; //TODO Make Answer Random coinToss(); break; } //TODO Test The Above if(Coin == Heads && (Choice == heads)) { System.out.println("You have won the coin toss!"); Toss = Yes; }else if (Coin == Heads && (Choice == tails)){ System.out.println("You have lost the coin toss..."); Toss = No; } if(Coin == Tails && (Choice == tails)) { System.out.println("You have won the coin toss!"); Toss = Yes; }else if (Coin == Tails && (Choice == heads)){ System.out.println("You have lost the coin toss..."); Toss = No; } if(Toss == Yes) { //Insert Something here }else if(Toss == No) { //Insert Something here } } public static void coinToss() { Random coin = new Random(); int coinRand = coin.nextInt(2); if (coinRand == 0) { System.out.println("The Result was Heads...."); Coin = Heads; }else{ System.out.println("The Result was Tails...."); Coin = Tails; } } }