Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise This lab is designed to give you practice implementing loops, input val

ID: 3654736 • Letter: E

Question

Exercise This lab is designed to give you practice implementing loops, input validation, and also introduces you to the Math classes' random() method. In this lab you will use create a dice rolling simulator using the loops of your choice and Java's random number generator. int die = (int)(Math.random() * 6 + 1); will result in either 1, 2, 3, 4, 5, or 6. Make sure you understand why. Getting Started To start this exercise, you should Open eclipse and start a new Java project named Lab08 Add a Class (named Lab08) to this project. Problem Description Your program should do the following: Propmpt the user to enter the number of times to roll a six-sided die. The user can roll a die no more than 10 times. If the user inputs a value less than 1 or greater than 10, the user should be prompted again until an "valid" input value is read. Use a loop that iterates the appropriate number of times and does the following: "rolls the die" by getting a random value between 1 and 6 adds the roll value to a variable that keeps track of the sum of all roll values outputs the roll value increments a counter variable used to keep track of how many times the loop has iterated After all rolls have completed, compute and output the average roll value. Once you have written your program: Make sure that your programs compile and run without errors or warnings. Run your program enough times to ensure that the appropriate die values are displayed and that the average is computed correctly. If it runs correctly, then see your TA for a check-off. Sample run(s): Enter number of rolls (1-10): 5 Roll: 5 Roll: 3 Roll: 5 Roll: 3 Roll: 6 Average roll: 4.4 ------------------------- Enter number of rolls (1-10): 0 Invalid entry! Enter number of rolls: 11 Invalid entry! Enter number of rolls: 10 Roll: 1 Roll: 6 Roll: 1 Roll: 3 Roll: 4 Roll: 2 Roll: 5 Roll: 1 Roll: 3 Roll: 5 Average roll: 3.1

Explanation / Answer

package Cramster; import java.util.Scanner; public class RollDice { private static int[] roll = new int[6]; public static void main(String args[]) { Scanner input = new Scanner(System.in); int NumberOfRolls; while(true) { System.out.printf("Enter number of rolls (1-10): "); NumberOfRolls = input.nextInt(); if(NumberOfRolls < 1 || NumberOfRolls > 10) { System.out.printf("Wrong Input. Try Again "); } else break; } for(int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote