Need some help Java, Pair Of Dice | Sololearn: Learn to code for FREE!

-3

Need some help Java, Pair Of Dice

Write a program that rolls a pair of dice until the sum of the number rolled is a specific number. We also want to know the number of times the dice are rolled to get the desired sum. The smallest number or each die is 1 and the larges number is 6. So the smallest sum of the numbers rolled is 2 and the largest sum of the numbers rolled is 12. We use the random number generator, to randomly generate a number between 1 to 6. a. Create a statement that randomly generates a number between 1 to 6 and stores that number into die1, which becomes the number rolled by die1. b. Similarly, create a statement that randomly generates a number between 1 to 6 and stores that number into die2, which becomes the number rolled by die2. c. Next, determine whether sum contains the desired sum of the numbers rolled by the dice. If does not contain the desired sum, then we roll the dice again. (This can be accomplish by using do while loop). d. Create a method named rollDice that takes as a parameter the desired sum of the numbers 0 https://code.sololearn.com/c89b49SFrQ6J/?ref=app

4/8/2022 9:48:35 AM

Carlo Jade

7 Answers

New Answer

+2

Name your class Dice or RollEm but decide for one. You haven't used the set-method anywhere. You need a variable for the "desired sum". Run a while loop and roll dice on each iteration. If the sum of the current roll is equal to the desired sum, break, else keep rolling the dice. If the loop works, you can put it in an own function to meet task d).

+1

Well, then write a program... If you need help, please LINK your code so we can see what is going on

+1

Carlo Jade Please put it in a script on sololearn playground and link it HERE IN THE THREAD. Not in DM

0

https://code.sololearn.com/c89b49SFrQ6J/?ref=app

0

Here I'm sorry i forgot to link it

0

Hooow can you edit my code?

0

Start by fixing your class name and making a variable for desired sum. Carlo Jade start by doing the above and then link our updated code, so we can do the rest.