I am currently trying to roll 5 dice 100,000 times and output the number of times each possible total (of dots/pips) occurs. It seems to output the incorrect thing and isnt counting the occurrences properly.
public class lab_DiceRollTest {
public static void main(String[] args) {
int total;
int total2;
String valid;
String isDifferent;
int rolls = 100000;
int d = 0;
The program is supposed to generate random dice rolls using the get and set methods. If the user doesn't specific how many sides the dice have, then it defaults at 6 with the constructor. The program runs but its generating 0's.
import java.util.Scanner; public class RollOfTheDice { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Time to roll the dice, how many sides do they have?"); int numSides = input.nextInt();
Create a class called DiceStatistics to represent a pair of dice and the totals of their rolls. It should have an array of two Dice as a private data member (these are the Dice from Problem 1). It should also have, as a data member, an array of integers to represent the possible totals of rolling two dice.
The class should also have the following methods:
initStats() to initialize all the totals to zero. rollOnce() to roll each die once, and add one to the correct totals element printStatistics() to print the number of times each total has come up over the number of runs.
Here is my code:
public class DiceStatistics { private final int NUMBER_OF_DICE = 2; private Dice[] dice = new Dice[NUMBER_OF_DICE]; private int[] totals; private int numberOfRolls;
[Code] ....
And here is the error:
run: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: Dice.roll at DiceStatistics.rollOnce(DiceStatistics.java:27) at DiceStatistics.main(DiceStatistics.java:55) Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)
I know it has something to do with the fact that I need to somehow import the information from my first program "Dice" into this in order to actually get the dice statistics, but how do I do that?
I'm finishing up this assignment, and I'm stuck. These are the last 2 instructions:
. Roll each of the Dice by invoking the roll method on each Dice in the array. . Keep track of the totals sum of all the dice in the array. Be sure to roll the dice array at least 10000 times.
How to finish it up?
Here's my code so far:
package homework3;
import java.util.Random; public class Dice { private int numberShowing; private final int numberOfSides; private static final Random randomNumber = new Random(); public Dice() { numberOfSides = 6;
I need to create a simply application that would display the results of two dice thrown five times and the total of those results. This is shown below in the attached file.
The problem is, I have a do-while loop that loops 6 times. Inside the loop, I have 2 random.nextInt(5) that generate random numbers. But how can I output the total? How can I make a variable equal to the sum of the two random numbers if the two random numbers are located inside a do-while loop?
Attached below is also the code I have thus far.
(Attached below is both files: what it needs to look like, and what it currently looks like)
How would I program a counter that will return the total number of search, failed searches and correct searches. The second thing is how can a return the price of the search methods with out calling for it specifically. Here is my current code.
package stu.paston.program7; import java.util.Scanner; public class MainClass { public static void main(String[] args) { InventoryClass productData= new InventoryClass();
I cannot get the right output for my program. I need to get the total number of pennies in dollar amount for the output of Total Pay. This is my program. The directions are:
Write a program that calculates the amount a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies. Do not accept a number less than 1 for the number of days worked.
import java.util.Scanner; import java.text.DecimalFormat; public class PenniesForPay { public static void main(String[] args) { int numDays;
[Code] ....
totalSalary should be total number of pennies / 100....However its not picking up only day 30 of pennies which is 536,870,912 pennies and then dividing it?
I'm struggling with inheritance in my assignment. The assignment states that I should use the calculatePrice() to calculate the total price and use another method to display the total. The I must overload the calculatePrice() and add a fee in the SpeedOrder() class.
My main class
package useorder; import javax.swing.*; public class UseOrder { /** * @param args the command line arguments */ public static void main(String[] args) { Order.display();
[Code] .....
The problem is mainly displaying the TotalPrice field and. I can't display TotalPrice if it's not static but if it's static I can't inherit it to the SpeedOrder class to assign the total in the overloaded calculateprice method. How can I display the total in my order class and use it in my SpeedOrder class?
Write a method called statistic that simulates the rolling of two dice 1000 times. (1000 times is a parameter of the method statistic).The program should have no input, and should use pseudo random numbers to simulate the rolls (one random number per die). Store the sum resulting from each roll of two dice, determine the number of times each 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, and 12 was rolled. The out produced by the program is:
public static void main(String[] args) { statistic(1000); } public static void statistic(int number) { Random randomNumbers = new Random();
[code]...
i have been trying for hours to make it look like the output above but no luck. I was wondering if there's any other way writing the code without using arrays.
The instructions are to "write a program to simulate tossing a pair of 11-sided dice and determine the percentage of times each possible combination of the dice is rolled... then ask the user to enter the number of sides on a die" The code is all provided here, I just have to put it in the right spots. (Side note, I cannot use arrays.) Here's the original file I was given to work with:
Java Code:
import java.util.Random; import java.util.Scanner; public class DiceProbability { public static void main(String[] args) { //Declare and initialize variables and objects //Input: ask user for number of rolls and number of sides on a die //Print heading for output table
[Code] ....
When I run it, I get something like this (just a part of my output):
Please enter the number of sides on a die: 6 Please enter the number of rolls: 2
I want to write a small Hi Lo Betting Dice program that satisfies these conditions :
A player places a bet on whether the sum of two dice will come up High (totalling 8 or higher), Low (totalling 6 or less) or Sevens (totalling exactly 7). If the player wins, he receives a payout based on the schedule given in the table below:
Choice Payout High 1 x Wager Low 1 x Wager Sevens 4 x Wager
The player will start with $100 for wagering. If the player chooses to wager $0 or if he runs out of money, the program should end. Otherwise it should ask him whether he's wagering on High, Low or Sevens, display the results of the die rolls, and update his money total accordingly.
some sample output:
You have 100 dollars. Enter an amount to bet (0 to quit): 50 High, low or sevens (H/L/S): H Die 1 rolls: 1 Die 2 rolls: 5 Total of two dice is: 6 You lost!
You have 50 dollars. Enter an amount to bet (0 to quit): 25 High, low or sevens (H/L/S): L Die 1 rolls: 6 Die 2 rolls: 2 Total of two dice is: 8 You lost!
You have 25 dollars. Enter an amount to bet (0 to quit): 12 High, low or sevens (H/L/S): H Die 1 rolls: 2 Die 2 rolls: 6 Total of two dice is: 8 You won 12 dollars!
I have written some code but now i am stuck at the logic ...
package com.peg.hilodice; import java.util.Scanner; public class DiceGame { public static void main(String[] args) { // TODO Auto-generated method stub int money = 100; int bet;
I am making a Dice Roll GUI and I have most of it down and I only need this constructor to work for the program to work (I think). I don't know where to place the constructor, I tried placing it around the RollButton class but it still didn't work and gave me java error constructor in class cannot be applied to given types
Here's my constructor:
private JPanel panel; public RollButton(JPanel panel){ this.panel = panel; }
package dicedemo; public class DiceDemo { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here
final int Die1_SIDES = 6; // Number of side of dice 1 final int Die2_SIDES = 6; // Number of side of dice 2 // Create two instances of the Die class.
[Code] ....
I need converting the number output to text: example one, two, three, etc.
I have this really a graphics program that I'm working on which displays a single die, and right now it is set to the default 6 sides. I need to change it to 12. Here is the program:
/** * This class encapsulates a simple dice game. The number of dice and number of sides on those dice are given by instance variables. The outcomes ArrayList holds a list of all possible outcomes of throwing that number of dice with that number of sides. * * If there were 2 dice, each with 6 sides, then possible outcomes would include 1 1, 1 2, 1 3, 1 4, 1 5, 1 6, 2 1, 2 2, 2 3, and so on. * * Your task is to complete the methods that calculate the possible outcomes. One method calculates outcomes allowing for repeated numbers. One method calculates the outcomes of a fictional dice game where repeated numbers cannot occur. * * You must use recursion. This is a variation on the permutations problem from the book. */
public class Dice { private static int numberOfSides; private static int numberOfDice; public ArrayList<String> outcomes;
[code]...
I manage to calculate the numberOfOutcomes correctly, but then get a nullPointerException. Also, is there a way that I can use getNumberOf Outcomes without making it static? The testing code that the teacher provided is using it in another class and if I make it static, then it doesn't work in that file.
what code I should add to my program in order to get these dice to roll. The program, according to my teacher, is CORRECT so far, so I'm not going to change anything. I just need to know how to roll the 2 dice I added in. I just want to get it done. No math.Random. The direction is: Roll each of the Dice by invoking the roll method on each Dice in the array.
My code:
//Dice.java package homework3; import java.util.Random; public class Dice { private int numberShowing; private int numberOfSides; private static final Random randomNumber = new Random();
Write a program that rolls two dice, adds the numbers and prints out the results. I have managed to do this but we have to make it a horizontal table instead of a vertical one. like the attached file "CORRECT", right now i only get the "NOTCORRECT". i have tried for hours to fix this but i can't.
import java.util.Random;
public class Statistikk { public static void skrivStatistikk() { Random rand = new Random(); int[] antall = new int[13]; {
[Code] .....
(Antall is basically frequency|side is the same as a face of a die)
Here is my code, does my code need improvement? Or is it my printf that is the issue? i've tried deleting the 's and adding the printf to the same line, but nothing worked.
I'm writing a program that is about rolling "dice" and getting the scores to add up to 100. There are two players in the game and each must take turns rolling dice choosing whether or not to keep rolling dice and accumulating more points during their turn while risking their points being lost by rolling a 1 or to add their turn points to their total points. The question I have is how would I exit the do while loop if the player chooses to add their turn score, thus adding their score and ending their turn?
Here is the coding so far.
Java Code:
import java.util.Scanner; import java.util.Random; public class Pig { public static void main(String[] args) { int die; int userTotalScore; int userTurnScore; int compTotalScore; int compTurnScore;
import java.util.Random; import java.util.Scanner; public class DiceGame6 { public static void main(String[] args){ Scanner stdIn = new Scanner(System.in); System.out.println("Welcome to Computer Dice!"); System.out.println("-------------------------------"); System.out.println("You will first roll your dice
[code]....
How would I get the code to count the number of times something occurred. In the end it's suppose to count how many times I played the game and how many times I've won vs lost.
I am trying to figure out how to simulate an ability score calculation for an RPG character creation. The way I want to do it is to have 5 d6 dice rolled and then the best three of the 5 rolls are added together for a maximum of 18 points and a minimum of 3 points.
Now I know how to generate random numbers, but I do not know how to have the best 3 picked out. What I have right now is super simple.
package javaapplication12; import java.util.Random; public class JavaApplication12 { /** * @param args the command line arguments */ public static void main(String[] args) {
[Code] ....
So this gives me my five rolls but then have the code pick out the best three every time the program is run is kind of an issue for me.
my assignment is to code a program to simulate the rolling of 2 dice. I have most of it set but when I run it and have it print out how many times each number (2-12) was rolled, it displays the numbers 1 off. for instance it will display the number of 4s rolled next to the 5s.
here it is
import java.util.Scanner; //allows info to be inputted// import java.util.Random; //opens random number generator// public class RollTheDiceWithArray13 {
Write a program to simulate the rolling of two dice. The program should use Math.random (google how to use Math.random if needed) to roll the first die and should use Math.random again to roll the second die. The sum of the two values should then be calculated your program should roll 50,000 times. Use a single dimensional array to tally the numbers of times each possible sum appear(the possible values are 2 through 12, think about why?). Print the results in a tabular format.
Here's the code I'm working on so far:
public class RollingDice{ public static void main(String[] args){ int die1; int die2; int roll; die1 = (int)(Math.random()*6) + 1; die2 = (int)(Math.random()*6) + 1; roll = die1 + die2; System.out.println("The roll of the first dice is: " + die1); System.out.println("The roll of the second dice is: " + die2); System.out.println("Your total roll is: " + roll); } }
What am I missing at this point, and what parts did I do wrong to change it?
import java.util.Random; /** * A very basic Dice that can be rolled and represent int values */
public class Dice{ private Random rand; public Dice(){ rand=new Random(); } /**simulates rolling the dice*/
[Code] ....
Why the Random rand is initiated at the Constructor and not at roll? Like the code works for both but I remember our teacher telling us something about one uses more memory than the other.
I am having a problem with my java program. My goal is to request the user to enter how many times they want to roll a pair of dices. Each dice have numbers 1-6. When rolling the dices, I randomly pick a number from each dice and total the number. My goal is to calculate the number of times snake-eyes was rolled which is a total of 2 and total number of times a total of 7 was rolled. Here is my code. I am calling the rollDice method to perform the random pick and calculations. The error I am getting is at the bottom of the code.
package dice; import java.util.Scanner; import java.util.Random; public class Dice { public static void main(String[] args) { int numRolls; // number of rolls
[code]...
How many times would you like to roll the two dice? 1000 Exception in thread "main" java.lang.NullPointerException at dice.Dice.main(Dice.java:40) Java Result: 1 BUILD SUCCESSFUL (total time: 4 seconds)
Dice are used in many games. One die can be thrown to randomly show a value from 1 through 6.
Design a Die class that can hold an integer data field for a value (from1 to 6).
Include a constructor that randomly assigns a value to a die object. Appendix D contains information on generating randomnumbers. To fully understand the process, you must learn more about Java classes and methods. However, for now, you can copy the following statement to generate a random number between 1 and 6 and assign it to a variable. Using this statement assumes you have assigned appropriate values to the static constants.
Also include a method in the class to return a die's value. Save the class as
Die.java.
Write an application that randomly "throws" two dice and displays their values. After you read the chapter Making Decisions, you will be able to have the game determine the higher die. For now, just observe how the values change as you execute the program multiple times. Save the application as TwoDice.java.