DiceRoller.java

You are to write a program which will ask the user for the number and type of dice they would
like to roll in the form of “xdy”. The x represents the number of dice, and the y represents how
many sides the dice have. Your program MUST read the input as a string, then parse the data.
You may assume that the input is entered in the form of an integer, followed by the character “d”
followed by an integer.

Once you have the number of dice you will use the commands below to generate that many
random numbers between 1 and the largest number on the dice. You must display each value
that is rolled and then report the results to the user as well as the sum of all the rolls.

Input: Number and size of dice (String)

import java.util.Random;
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(n);<-- generates a random number between 0 and n-1
The program should ask for input and display output clearly and using English. For example:

Please enter the number and type of dice to roll.
5d8
Rolling: 2, 6, 1, 8, 6
The total amount rolled is 23.

I am having a lot of trouble and any help would be awesome :)

it would be nice if you would exert an effort doing it rather than typing that here, no one is gonna do your homework for you, you can atleast try,

it would be nice if you would exert an effort doing it rather than typing that here, no one is gonna do your homework for you, you can atleast try,

i know. im sorry. i didnt mean for it to appear that i wanted someone to do it for me... i have been trying at it for 4 days now. the parts i am having trouble with is getting "xdy" to appear and to get the rolling results to appear in the "2,3,4,5,6,etc" fashion. any help with that would be awesome!

i am having trouble with is getting "xdy" to appear

Hard to recommend changes to your code if there is no code to be changed.

Hard to recommend changes to your code if there is no code to be changed.

could u give me an example of how I would get "xdy" to appear?
I dont get how to save/keep the x and y the user would input.

an example of how I would get "xdy" to appear?

System.out.println(x + "d" + y); // show xdy

how to save/keep the x and y the user would input.

x = <what the user input>; // save what the user input in x

Edited 5 Years Ago by NormR1: n/a

This article has been dead for over six months. Start a new discussion instead.