There are 5 static variables: countAllGames, countWinCrosses, countWinNoughts, percentageWinCrosses and percentageWinNoughts. Their results are displayed in a "Statistics" window. There is one problem: the first 3 variables are normally their counters are incremented, as was intended, but the last two variables are dropping their result to 0.0. Here is the code:
if (countWinCrosses != 0) {
percentageWinCrosses = (countWinCrosses / countAllGames) * 100;
}
if (countWinNoughts != 0) {
percentageWinNoughts = (countWinNoughts / countAllGames) * 100;
}
And this is the code of methods, one of which is executed after winning the x's or o's:
public static void incrementWinCrosses() {
countWinCrosses++;
calculatePercentage();
}
public static void incrementWinNoughts() {
countWinNoughts++;
calculatePercentage();
}
There is also a method that increases the count of all games played. Why variables percentageCrosses and percentageNoughts become zero after the second call to calculatePercentage()? After the first winning one of them becomes equal to 100%, but after the second game (say, won the other) both variables are equal to 0.0. The first 3 variables retain their values, increasing each time by 1.