Hi, i'm new to coding with Java so keep that in mind. To practice I thought it would be a fun idea to create a super simple football simulator through the console that would just do a coin toss, then randomly decide if its going to be a Turnover (50%), and Field Goal (25%), or a Touch Down (25%). Then just to end it for now I made it so the game would stop when a team reaches 50 points or higher. Here is the code... (I use Eclipse IDE btw)
public class Simulator { public static void main(String[] args) { int touchDown = 7; int fieldGoal = 3; int homeScore = 0; int awayScore = 0; String total = "Home: " + homeScore + " Away: " + awayScore; boolean homeBall = false; boolean awayBall = false; double coinToss = Math.random(); if (coinToss <= 0.5){ homeBall = true; System.out.println("The home team won the coin toss!"); }else{ awayBall = true; System.out.println("The away team won the coin toss!"); } if (homeScore >= 50){ homeBall = false; awayBall = false; System.out.println("Final Score: Home " + homeScore + ", Away " + awayScore); } if (awayScore >= 50){ homeBall = false; awayBall = false; System.out.println("Final Score: Home " + homeScore + ", Away " + awayScore); } if (homeBall = true){ double homeChance = Math.random(); if (homeChance < 0.5){ homeBall = false; awayBall = true; System.out.println("Home turnover!"); } if (0.5 <= homeChance){ if (homeChance < 0.75){ homeScore = homeScore + fieldGoal; System.out.println(total); homeBall = false; awayBall = true; }else{ homeScore = homeScore + touchDown; System.out.println(total); homeBall = false; awayBall = true; } } } if (awayBall = true){ double awayChance = Math.random(); if (awayChance < 0.5){ homeBall = true; awayBall = false; System.out.println("Away turnover!"); } if (0.5 <= awayChance){ if (awayChance < 0.75){ awayScore = awayScore + fieldGoal; System.out.println(total); homeBall = true; awayBall = false; }else{ awayScore = awayScore + touchDown; System.out.println(total); homeBall = true; awayBall = false; } } } } }
The problem is that it always ends up stopping basically right after the first possession and its almost always a turnover too. I'm new to while/do statements so that might be related to the solution. I would appreciate anyone's help!