![objective: create methods that receive arrays as arguments. Problem Statement: Roll a 6-side die a user specified number of times and keep track of the number of times each value appears. Simulate rolling the die by generating a random number in the range of 1 to 6. After rolling the die the needed number of rolls, display a histogram of the distribution of roll values See the sample output below How many times o you want to ro the die Max value s 1 00 TRY AGAIN! Hou many times do you want to roll the die? [Max value is 100] 15 Lets get rolling The number of 1s 4 The number of 2s The number of 3s The number of 4 The number of 5s: 4 The number of 6s: 2 To begin, create a new project called Lab9-RollDie. Download and add the Roll Diejava starter code provided on Blackboard.](http://img.homeworklib.com/questions/7da18020-753e-11eb-88db-d7d93ac89f39.png?x-oss-process=image/resize,w_560)
the RollDie.java:
import java.util.Random;
import java.util.Scanner;
/*
* HEADER HERE !!
*/
public class RollDie {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
// Step 1: Declare and initialize array and
// initialize random number generator
int[] rollValueCounts = new int[7];
Random randGen = new Random();
// Step 2: Determine the number of rolls
System.out.print("How many times do you want to roll the die?");
System.out.print(" [Max value is 100] ");
int numRolls = scnr.nextInt();
// TODO: Check that user provided value is valid
// (i.e., in the range 0-100) and if not reprompt
System.out.println("Let's get rolling...");
// Step 3: Generate numRolls random values between 1-6
for(int i = 0; i < numRolls; i++) {
int rollValue = randGen.nextInt(6) + 1;
/* The rollValue will serve as the index and at that
location in the array we will keep the number of rolls
for that value.
*/
rollValueCounts[rollValue]++;
}
// TODO:
// Step 4: Display the roll counts as a histogram
//printTable(rollValueCounts);
}
// FOR LAB, CREATE A NEW METHOD TO DISPLAY THE ROLL COUNTS
// AS A HISTOGRAM. BE SURE TO STATE STEPS IN THE METHOD AND
// PROVIDE A HEADER
/**************************************************************************
* printTable - Prints the contents of an integer array as a table
*
* int[] data - The data to be displayed on the screen
*/
public static void printTable(int[] data) {
for(int i = 0; i < data.length + 1; i++) {
System.out.print("-----");
}
System.out.print("\nIndex");
for(int i = 0; i < data.length; i++) {
System.out.printf("|%4d", i);
}
System.out.print("\nValue");
for(int i = 0; i < data.length; i++) {
System.out.printf("|%4d", data[i]);
}
System.out.println();
for(int i = 0; i < data.length+1; i++) {
System.out.print("-----");
}
}
}
package com.company;
import java.util.Random;
import java.util.Scanner;
/*
* HEADER HERE !!
*/
public class RollDie {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
// Step 1: Declare and initialize array and
// initialize random number generator
int[] rollValueCounts = new int[7];
Random randGen = new Random();
int numRolls;
// Step 2: Determine the number of rolls
// (in the range 0-100) and if not reprompt
while(true) {
System.out.print("How many times do you want to roll the die?");
System.out.print(" [Max value is 100] ");
numRolls = scnr.nextInt();
if(numRolls>100)
System.out.println("Try Again!");
else
break;
}
System.out.println("Let's get rolling...");
// Step 3: Generate numRolls random values between 1-6
for (int i = 0; i < numRolls; i++) {
int rollValue = randGen.nextInt(6) + 1;
/* The rollValue will serve as the index and at that
location in the array we will keep the number of rolls
for that value.
*/
rollValueCounts[rollValue]++;
}
// Step 4: Display the roll counts as a histogram
printTable(rollValueCounts);
}
/**************************************************************************
* printTable - Display the roll counts as a histogram
*
* int[] data - The data to be displayed on the screen
*/
public static void printTable(int[] data) {
System.out.print("The number of 0's :" +data[0]);
for (int i = 0; i <data[0] ; i++) {
System.out.print(" *");
}
System.out.println();
System.out.print("The number of 1's :" +data[1]);
for (int i = 0; i <data[1] ; i++) {
System.out.print(" *");
}
System.out.println();
System.out.print("The number of 2's :" +data[2] );
for (int i = 0; i <data[2] ; i++) {
System.out.print(" *");
}
System.out.println();
System.out.print("The number of 3's :" +data[3] );
for (int i = 0; i <data[3] ; i++) {
System.out.print(" *");
}
System.out.println();
System.out.print("The number of 4's :" +data[4] );
for (int i = 0; i <data[4] ; i++) {
System.out.print(" *");
}
System.out.println();
System.out.print("The number of 5's :" +data[5]);
for (int i = 0; i <data[5] ; i++) {
System.out.print(" *");
}
System.out.println();
System.out.print("The number of 6's :" +data[6] );
for (int i = 0; i <data[6] ; i++) {
System.out.print(" *");
}
System.out.println();
}
}
output:-->![How many times do you want to roll the die? [Max value is 100] 200 Try Again! How many times do you want to roll the die? [Ma](http://img.homeworklib.com/questions/81aed860-753e-11eb-a206-31b151da9a6b.png?x-oss-process=image/resize,w_560)
the RollDie.java: import java.util.Random; import java.util.Scanner; /* * HEADER HERE !! */ public class RollDie {...
package week_4; import input.InputUtils; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Random; import static input.InputUtils.positiveIntInput; import static input.InputUtils.yesNoInput; /** Write a program to roll a set of dice. Generate a random number between 1 and 6 for each dice to be rolled, and save the values in an ArrayList. Display the total of all the dice rolled. In some games, rolling the same number on all dice has a special meaning. In your program, check if all dice have the same value,...
import java.util.Scanner;
public class Lab6d {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
// TODO: get user choice
// TODO: call printTable method passing choice as the
parameter
}
public static void printTable(int stop) {
// TODO: print header
// TODO: loop to print table rows up to stop value
}
Write a Java program where the main () method prompts the user to select an integer value between 1 and...
import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...
import java.util.Scanner; public class Chpt7_Project { public static void bubbleSort(int[] list) { int temp; for (int i = list.length - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (list[j] > list[j + 1]) { temp = list[j]; list[j] = list[j + 1]; list[j + 1] = temp; } } } ...
import java.util.Scanner; public class TriangleMaker { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle."); Scanner keyboard = new Scanner(System.in); int size = keyboard.nextInt(); for (int i = 1; i <= size; i++) { for (int j = 0; j < i; j++) { System.out.print("*"); } System.out.println(); } for (int...
import java.util.Arrays; import java.util.Random; import java.util.Scanner; /** * TODO Write a summary of the role of this class in the * MasterMind program. * * @author TODO add your name here */ public class MasterMind { /** * Prompts the user for a value by displaying prompt. * Note: This method should not add a new line to the output of prompt. * * After prompting the user, the method will consume an entire * line of input while reading...
SIMPLE: PSEUDOCODE FOR THE CODE BELOW Bingo.java package bingo; import java.util.Scanner; import java.util.Random; public class Bingo { public static BingoCard gameCard; public static int totalGamesWon = 0; public static void main(String[] args) { //Use do-while loop to do the following: //1. instantiate a gameCard //2. call the method playGame() //3. call the method determineWinner() //4. Ask user if they wish to play again? (1 = yes; 2 = no)...
Make a FLOWCHART for the following JAVA Prime Number Guessing Game. import java.util.Random; import java.util.Scanner; public class Project2 { //Creating an random class object static Random r = new Random(); public static void main(String[] args) { char compAns,userAns,ans; int cntUser=0,cntComp=0; /* * Creating an Scanner class object which is used to get the inputs * entered by the user */ Scanner sc = new Scanner(System.in); System.out.println("*************************************"); System.out.println("Prime Number Guessing Game"); System.out.println("Y = Yes , N = No...
Complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * This returns a string containing the char ch, count times. * For example calling with 'a', 5 would return: * "aaaaa" * * @param ch The character to repeat. * @param count The number of the character. * @return A string with count number of ch. */ public static String charToString(char ch, int count) { return null; //TODO }
Please Help! I need to update the code below to meet these criteria! 1. The constructor of die class initializes face of Die to 3 2. roll method updates face of die to value from 1-6 3. getFace() method provides current face to the main program 4. main create a Die object 5. main create a Die object 6. main rolls die 5 times 7. main computes sum of rolls 8. main computes actual average of the rolls <--------- Code...