The goal for this class is to have an int with a desired number of rolls. From this number the class will roll 5 dice and determine if the rolls are a yahtzee, full house, large straight, four of a kind, three of a kind, or nothing (loser). Where I'm having trouble is building a proper if statement to vet the large straights and the loser rolls. Those rolls always produce numbers that are vastly bigger than the initial test of 5000 rolls. Any help would be greatly appreciated. Below is my Yahtzee class and then below that is my current driver.
public class Yahtzee {
public int rolls;
public void getYahtzee(int rolls){
int yahtzee = 0;
int fullHouse = 0;
int largeStraight = 0;
int four = 0;
int three = 0;
int losers = 0;
for (int i = 0; i <= rolls; i++){
int dice1=(int)(Math.random()*6+1);
int dice2=(int)(Math.random()*6+1);
int dice3=(int)(Math.random()*6+1);
int dice4=(int)(Math.random()*6+1);
int dice5=(int)(Math.random()*6+1);
int[] dice = new int[]{dice1, dice2, dice3, dice4, dice5};
int[] counts = new int[6];
for (int x=0; x<5; x++)
counts[dice[x]-1]++;
boolean check2 = false;
boolean check3 = false;
boolean check4 = false;
for (int x: counts) {
check2 |= (x==2);
check3 |= (x==3);
check4 |= (x==4);
if (x==5) {
yahtzee += 1;
} else if (x==1) {
largeStraight += 1;
} else if(check2 && check3) {
fullHouse += 1;
} else if (x==3) {
three += 1;
} else if (x==4){
four += 1;
} else if (x==0){
losers += 1;
}
}
}
double percentage1 = (double)yahtzee/(double)rolls;
double percentage2 = (double)fullHouse/(double)rolls;
double percentage3 = (double)largeStraight/(double)rolls;
double percentage4 = (double)four/(double)rolls;
double percentage5 = (double)three/(double)rolls;
double percentage6 = (double)losers/(double)rolls;
System.out.println("Number of Rolls: " + rolls);
System.out.println("----------------------------");
System.out.println("Number of Yahtzees: " + yahtzee);
System.out.println("Yahtzee Percentage: " + percentage1 + "%" + "\n");
System.out.println("Number of Full Houses: " + fullHouse);
System.out.println("Full House Percentage: " + percentage2 + "%" + "\n");
System.out.println("Number of Large Straights: " + largeStraight);
System.out.println("Large Straight Percentage: " + percentage3 + "%" + "\n");
System.out.println("Number of Four of a Kinds: " + four);
System.out.println("Four of a Kind Percentage: " + percentage4 + "%" + "\n");
System.out.println("Three of a Kind: " + three);
System.out.println("Three of a Kind Percentage: " + percentage5 + "%" + "\n");
System.out.println("Number of Losers: " + losers);
System.out.println("Losers Percentage: " + percentage6 + "%" + "\n");
}
}
/* This is my driver class */
public class Driver {
public static void main(String[] args){
Yahtzee yt = new Yahtzee();
yt.getYahtzee(5000);
}
}