Question

home / study / engineering / computer science / computer science questions and answers / Write...

home / study / engineering / computer science / computer science questions and answers / Write A Second Game Program That Prints A Chart To The Screen Showing The Randomness Of A Die. ... Question: Write a second game program that prints a chart to the screen showing the randomness of a die. Th... Write a second game program that prints a chart to the screen showing the randomness of a die. The game should first prompt the client for a number of die throws that he would like. The game then throws the die that many times. The game then prints a chart showing a line of asterisks for each die number, indicating the number of times the die landed with that face number on top. If the die behaves in a truly random fashion, each chart will look a little different, reflecting the randomness of the die. Allow the client to repeat the game as many times as she wishes. Use methods to simplify the code. Any group of lines of code that is repeated is a prime candidate for a method. Guarantee the number entered is not less than zero. Do not use arrays.

Your program should duplicate the output found below: This game requests a number from the player. The game then throws the dice that number of times. The game then displays a chart showing the number of times the six dice faces appeared given the number of throws.

Please enter the number of times that you would like the computer to throw the dice.

100 A chart of 100 throws.

dice number 1: ****************

dice number 2: ********

dice number 3: ******************

dice number 4: *****************

dice number 5: *********************

dice number 6: ********************

Would you like to play the game again? Please enter (yes/no).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

import java.util.Random;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

while(true) {

System.out.println("Please enter the number of times that you would like the computer to throw the dice: ");

int n = sc.nextInt();

Random random = new Random();

int one = 0, two = 0, three = 0, four = 0, five = 0, six = 0;

for (int i = 1; i<= 100; i++) {

int face = random.nextInt(6);

switch(face) {

case 0:

one ++;

break;

case 1:

two ++;

break;

case 2:

three ++;

break;

case 3:

four ++;

break;

case 4:

five ++;

break;

case 5:

six ++;

break;

}

}

System.out.printf("A chart of %d throws\n.", n);

System.out.print("Dice number 1: ");

for (int i=0; i<one; i++) {

System.out.print("*");

}

System.out.println();

System.out.print("Dice number 2: ");

for (int i=0; i<two; i++) {

System.out.print("*");

}

System.out.println();

System.out.print("Dice number 3: ");

for (int i=0; i<three; i++) {

System.out.print("*");

}

System.out.println();

System.out.print("Dice number 4: ");

for (int i=0; i<four; i++) {

System.out.print("*");

}

System.out.println();

System.out.print("Dice number 5: ");

for (int i=0; i<five; i++) {

System.out.print("*");

}

System.out.println();

System.out.print("Dice number 6: ");

for (int i=0; i<six; i++) {

System.out.print("*");

}

System.out.println();

System.out.println("Would you like to play the game again? Please enter (yes/no): ");

String cont = sc.next();

if ("no".equalsIgnoreCase(cont)) {

break;

}

}

}

}

Add a comment
Know the answer?
Add Answer to:
home / study / engineering / computer science / computer science questions and answers / Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • home / study / engineering / computer science / computer science questions and answers / write...

    home / study / engineering / computer science / computer science questions and answers / write a python program that generates a list of 50 random numbers. the program should display ... Question: Write a python program that generates a list of 50 random numbers. The program should display (wi... Write a python program that generates a list of 50 random numbers. The program should display (with labels) the sum, average, largest, and smallest of the list along with the...

  • home / study / engineering / computer science / computer science questions and answers / in...

    home / study / engineering / computer science / computer science questions and answers / in basic c please with comments so i can redo it on my own, thank you! for this lab, you only ... Question: In basic C please with comments so I can redo It on my own, thank you! For this lab, you only nee... In basic C please with comments so I can redo It on my own, thank you! For this lab, you...

  • home / study / engineering / computer science / computer science questions and answers / this...

    home / study / engineering / computer science / computer science questions and answers / this is a data modeling exercise i am assigned a project as a dba to design a data model to ... Question: This is a Data Modeling exercise I am assigned a project as a DBA to design a data model to suppo... This is a Data Modeling exercise I am assigned a project as a DBA to design a data model to support a...

  • home / study / engineering / computer science / computer science questions and answers / customer...

    home / study / engineering / computer science / computer science questions and answers / customer customerid,lastname,firstname, address,city,state,zip,email houses houseid, price ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: Customer Customerid,lastname,firstname, address,city,state,zip,email Houses Houseid, price range,... Customer Customerid,lastname,firstname, address,city,state,zip,email Houses Houseid, price range, regionid, housename, bedroom no., pool, address, city,state,zip Reservations reservationid, customerid, date reservation, discount, start date, end date House amenities houseid, amenities id Price Range- houseid,price,start date,...

  • home / study / engineering / computer science / computer science questions and answers / l(a)...

    home / study / engineering / computer science / computer science questions and answers / l(a) be the language generated by g(a) - (n, 2, s, p) where 2 - [a, b), n= {s,x) and s->axb ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: L(a) be the language generated by g(a) - (n, 2, s, p) where 2 - [a, b), n= {s,x) and s->axb ..... l(a) be the...

  • Can someone upload a picture of the code in matlab Write a "Guess My Number Game"...

    Can someone upload a picture of the code in matlab Write a "Guess My Number Game" program. The program generates a random integer in a specified range, and the user (the player) has to guess the number. The program allows the use to play as many times as he/she would like; at the conclusion of each game, the program asks whether the player wants to play again The basic algorithm is: 1. The program starts by printing instructions on the...

  • Can anyone help me with this java program? We are still very early with lessons so...

    Can anyone help me with this java program? We are still very early with lessons so no advanced code please. And if you comment throughout the code that would be incredibly helpful. Thank you Create 2 Java files for this assignment: Die.java and TestDie.java Part 1 - The Die Class             The program Design a Die class that contains the following attributes: sides: represents how many sides a dice has. A dice usually has 6 sides but sometimes could have...

  • Jubail University College Computer Science & Engineering Department Assessmen Assignment Course Code CS120/C5101 t Type: 1...

    Jubail University College Computer Science & Engineering Department Assessmen Assignment Course Code CS120/C5101 t Type: 1 Semester: 403 Course Title Programming Submission 27-06-2020 Total Points 8 Date Submission Instructions: • This is an individual assignment. • Please submit your program (Java fle) in Blackboard. You can create one java project, named as Assignment1_id and add separate java file for each question. You can name your javá files as 01.02.... etc. • Make sure that you include your student ID name...

  • question 2 in C programming please PE-05b-01 (Six-sider) write a counter-controlled program that prompts the user...

    question 2 in C programming please PE-05b-01 (Six-sider) write a counter-controlled program that prompts the user to enter the number of times n to roll a six-sided die. The program should print to the screen the iteration of the loop and result for each roll 1 ) How many times would you like to roll? 3 roll 6 6 5 1 2) PE 05b 02 (Flash Cards) Write a counter-controlled program that creates addition problems for an elementary kid to...

  • C# Code: Write the code that simulates the gambling game of craps. To play the game,...

    C# Code: Write the code that simulates the gambling game of craps. To play the game, a player rolls a pair of dice (2 die). After the dice come to rest, the sum of the faces of the 2 die is calculated. If the sum is 7 or 11 on the first throw, the player wins and the game is over. If the sum is 2, 3, or 12 on the first throw, the player loses and the game is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT