Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!