Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE USE replit IDE to troubleshoot the code This program is about a dice game. I dont know why am getting an error when i

PLEASE USE replit IDE to troubleshoot the code

This program is about a dice game. I dont know why am getting an error when i run the code on replit IDE. Please Can an expert help me correct the code. Thanks

HERE IS CODE :

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

// Create variables

int comDieSides; // Number of sides for the computers die

int userDieSides; // Number of sides for the users die

int maxRolls; // Number od times to roll

String winner;

String grandWinner;

int numUserWins = 0; // initializing variable for the of wins the user gets

int numComWins = 0; // initializing variable for the of wins the computer gets

int ties = 0;

// Creating scanner object

Scanner sc = new Scanner(System.in);

// Getting input from the user

System.out.println("How many sides does the user's die have?");

userDieSides = sc.nextInt();

System.out.println("How many sides does the computer's die have?");

comDieSides = sc.nextInt();

System.out.println("How many rolls do you wish to simulate?");

maxRolls = sc.nextInt();

// Create two instances of the Die class.

Die userDie = new Die(userDieSides);

Die comDie = new Die(comDieSides);

// Display the initial parameters of the dice.

System.out.println(

"This will roll a users " + userDieSides + " sided die and the computers " + comDieSides + " sided die.");

// Rolling the dice 10 times

System.out.println("Rolling the dice " + maxRolls + " times.");

System.out.println("User \tComputer");

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

// Rolling the dice.

userDie.roll();

comDie.roll();

// Declaring the winner by using if statements.

if (userDie.getValue() > comDie.getValue()) {

winner = "The user won.";

numUserWins++;

} else if (userDie.getValue() < comDie.getValue()) {

winner = "The computer won.";

numComWins++;

} else {

winner = "The roll is a tie.";

ties++;

}

// Outputting the value of the dice and the winner of that roll.

System.out.println(userDie.getValue() + "\t\t" + comDie.getValue() + "\t\t" + winner);

}

// Finding grand winner

if (numUserWins > numComWins) {

grandWinner = "the user";

} else if (numUserWins < numComWins) {

grandWinner = "the computer";

} else {

grandWinner = "no one. It is a tie";

}

// Display the results

System.out.println("The user won " + numUserWins + " times.");

System.out.println("The computer won " + numComWins + " times.");

System.out.println("There were " + ties + " ties.");

System.out.println("The grand winner is " + grandWinner + ".");

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Explain the process planning.

Answered: 1 week ago

Question

What do you mean by 'make or buy decision ' ?

Answered: 1 week ago