1 6 1) Trace the game. 2) Just give the answer. Please enter 1 or 2 Please enter the dice face number that you would like to be repeated. Please enter the number of times that you would like 6 to appear in a row. 3 You got a 1 Number of times in a row so far is 0 Number of throws is 1 You got a 6 Number of times in a row so far is 1 Number of throws is 2 You got a 2 Number of times in a row so far is 0 Number of throws is 3

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need help fixing a java program that includes an if and else statement where it shows the process and the other just prints the number of throws it took:

Version 1 section

Java code:

import java.util.Scanner;
  public class Part_2 {
      
   public static void main(String[] args) {
    int diceFaceNumber, numTimes, numThrows;
    
    
  System.out.print("                 This game throws a dice until a particular dice face number");
  System.out.print("                 appears in a row a certain number of times.");

  System.out.print("Please enter the version you want:");
  
  System.out.print("  1) Trace the game.");
  System.out.print("  2) Just give the answer");
  System.out.print("Please enter 1 or 2");
  
    if (input == 1);
    
    
    Scanner input = new Scanner(System.in);
    System.out.print("Please enter the die face number you would like to be repeated. ");
    
    diceFaceNumber = input.nextInt();
    System.out.print("How many times you want that die face number to appear in a row? : ");
    
    
    
    numTimes = input.nextInt();
    numThrows = computeNumThrows(diceFaceNumber, numTimes);
    printOutput(diceFaceNumber, numTimes, numThrows);
    
    
   }
   private static int computeNumThrows(int diceFaceNumber, int numTimes) {
    int numThrows = 0;
    int count = 0;
    while (count < numTimes) {
     int die = (int)(Math.random() * 6) + 1;
     
     
     
     
     numThrows++;
     if (die == diceFaceNumber)
      count++;
     else
      count = 0;
    }
    return numThrows;
   }
   private static void printOutput(int diceFaceNumber, int numTimes, int numThrows) {
    System.out.println("It took " + numThrows + " throws to get " + numTimes + " " + diceFaceNumber + "'s in a row.");
  
    System.out.println("                     Would you like to play the game again?     ");
    System.out.println("                                Please enter (yes/no)");
   }
  }

 

1
6
1) Trace the game.
2) Just give the answer.
Please enter 1 or 2
Please enter the dice face number that you would like to be repeated.
Please enter the number of times that you would like 6 to appear in a row.
3
You got a 1
Number of times in a row so far is 0
Number of throws is 1
You got a 6
Number of times in a row so far is 1
Number of throws is 2
You got a 2
Number of times in a row so far is 0
Number of throws is 3
Transcribed Image Text:1 6 1) Trace the game. 2) Just give the answer. Please enter 1 or 2 Please enter the dice face number that you would like to be repeated. Please enter the number of times that you would like 6 to appear in a row. 3 You got a 1 Number of times in a row so far is 0 Number of throws is 1 You got a 6 Number of times in a row so far is 1 Number of throws is 2 You got a 2 Number of times in a row so far is 0 Number of throws is 3
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education