Hi everyone, I've been taking a Intro to Java class this year and been enjoying it, I recently had a assignment which was a simple dice game, however I was wondering if a few tweeks could be made.
- Could we ask the user how many dice they want to roll? If so how could that be implemented.
- Check if the outcomes are as expected.
I've been enjoying Java alot and would appreciate some help with these two questions and I'm sure it can be done! I just don't have the expertise to know what to do, but will one day hopefully but a little help :) thanks.
Heres what I got so far, but it's only for one die.
public class DiceGame {
private static Scanner input;
public static void main(String[] args) {
// Declare variables for Scanner and Random
input = new Scanner(System.in);
Random random = new Random();
// Setup an array to hold the values from rolls. Declare a variable to hold the user's input,
// and another variable to hold the number generated by java.util.Random.
int[] frequency = new int[6];
int rolls;
int temp;
// Asks user for input on how many rolls they would like to make.
System.out.print("How many times do you want to roll the dice\n");
rolls = input.nextInt();
// for loop to go through the number of rolls user inputs.
for(int i = 0; i < rolls; i++) {
temp = random.nextInt(6);
frequency[temp]++;
}
// Display the number of rolls and results with a for loop.
System.out.print("Face\tFrequency");
for(int i = 0; i < 6 ; i++) {
System.out.println(i+1 + "\t" + frequency[i]);
}
}
}