I am having trouble figuring out how to write program code that will add up the number of doubles rolled, as well as the number of 7's rolled;the program already notifies the user which dice are 7's and which are doubles.
I know for the accumulation to work, it has to be an IF statement. I placed my IF statement within my MAIN method, but it does not seem to be working properly. For program running purposes only, I /* */ out the IF statement in case you wanted to copy and paste the program to see how it runs without the IF statement.
I am getting the hang of Java, but it's always tricky and confusing a bit.
import java.util.Random; public class DiceGame { public static void main(String [] args) { Random newnum = new Random(); int roll_1 = 0; int roll_2 = 0; int counter; boolean Doubles; int Doublecounter; System.out.println("Dice #1" + "\t" + "\tDice #2"); for(counter=1;counter<=10;counter++) { roll_1=1 + newnum.nextInt(6); roll_2=1 + newnum.nextInt(6); System.out.println(" "); System.out.print(roll_1); System.out.print("\t" + "\t" + " "); System.out.print(roll_2); Doubles(roll_1, roll_2); Seven(roll_2, roll_1); } /* int Doublescounter; if(Doublecounter > 1) { System.out.print("Number of doubles include: "); Doublescounter++; }*/ } public static boolean Doubles(int roll_1, int roll_2) { if(roll_1==roll_2) { System.out.print(" - Doubles were rolled."); return true; } else return false; } public static boolean Seven(int roll_1, int roll_2) { if((roll_1 + roll_2)==7) { System.out.print(" - The roll totaled 7."); int total1 = 0; return true; } else return false; } }