How to make an online Generator? What Program?

Help With My Die Rolling Java Program?

  • Hey could someone help me? I've got an assignment to make a program to roll one die, and I have the program upto here (see post below). I dont want to use the System.out.println codes, i rather display dialog boxes, as an extra for my teacher to hand out bonuses, lmao :P Here is the assignment question: Simulate rollong of one die; the output is to indicate the number of 1s, 2s ... 6s. Also display the percentage of all rolls that resulted in a 1; ... the percentage of all rolls that resulted in a 6. this is what i have: public abstract class DieRoll { public static void main(String[] args) { boolean run = true; Scanner reader = new Scanner(System.in); Random generator = new Random(); int dieNumber; int numDiceRolled; String input; String string = "yes"; input = JOptionPane.showInputDialog("Do you want to play with a die?"); dieNumber = Integer.parseInt(input); string = reader.nextLine(); while(string.equalsIgnoreCase ("yes") || string.equalsIgnoreCase ("ya") || string.equalsIgnoreCase ("y")){ input = JOptionPane.showInputDialog("How many times do you want to roll the die?"); numDiceRolled = reader.nextInt(); for (int counter = 0; counter < numDiceRolled; counter++) { dieNumber = generator.nextInt(6)+1; input = JOptionPane.showInputDialog("Die is a " + dieNumber); } input = JOptionPane.showInputDialog("Do you wish to roll again? [Y/N]"); string = reader.next(); } input = JOptionPane.showInputDialog("Thank you, Goodbye!"); } // end main() } // end class DieRoll Please note, I am only in grade 10, so all help is much appreciated! Thank you!

  • Answer:

    Well everything seems to be okay. If I was going to do this program I would: public class diceGame { public static void main(String[] args) { // simulate a random dice roll // create a while loop that will keep on rolling the dice //count the percentage of 1s, 2s, 3s, 4s, 5s, 6s in the while loop // exit while loop and display all percentage of each outcome of dice roll } } }

feRazz at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

goodluck with that

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.