Add Program In Order To Dice To Roll

May 8, 2014

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();

[code]....

View Replies


ADVERTISEMENT

Dice Roll GUI - Where To Place Constructor

Feb 17, 2014

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;
}

Here's my code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.Random;
import javax.imageio.ImageIO;

[code]....

View Replies View Related

All Possible Outcomes Of Dice Roll Using Recursion

Nov 26, 2014

Here is what I have so far:

/**
* 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.

View Replies View Related

Roll Two Dice / Add Them Together And Print The Result

Oct 23, 2014

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.

Attached image(s)

View Replies View Related

Simulating Roll Of D6 Dice With Java Code

Apr 21, 2015

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.

View Replies View Related

Program To Roll 1000 Times And Count How Many 7s Rolled

Nov 15, 2014

public class PairOfDice
{
private Die die1, die2;
public PairOfDice() {
die1 = new Die();
die2 = new Die();

[Code] .....

I am struggling with the final part of my code to get the dice to roll 1000 times and tell me how many times a 7 was rolled. I am getting these errors in jgrasp

----jGRASP exec: javac -g PairOfDice.java

PairOfDice.java:34: error: <identifier> expected
count = 0;
^
PairOfDice.java:35: error: illegal start of type
for (rep = 1; rep <= 1000; rep++) {

[Code] .....

22 errors

View Replies View Related

Multi-sided Dice - Keep Track Of Total Sum Of All Dice In Array

May 7, 2014

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;

[Code] ....

View Replies View Related

Hi Lo Dice Betting Program

Jun 29, 2014

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;

[Code] .....

View Replies View Related

Code A Program To Simulate Rolling Of 2 Dice

Jul 1, 2014

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
{
 
public static void main(String[] args)

[code]....

View Replies View Related

Java Program To Simulate Rolling Of Two Dice?

Feb 25, 2015

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?

View Replies View Related

Order Of Numbers - Reverse Array Program

Apr 23, 2015

import java.util.Scanner;

public class ReverseOrder {
public static Scanner input = new Scanner(System.in);
public static void main(String[] args){
int[] numbers;
double[] reverse;

numbers = readArray();
reverse = reverseOrder(numbers);

[Code] ....

I have to write a program that takes an order of numbers and print the reverse order of those numbers.

the out put i receive is:

How many numbers do you want to enter?
4
Please enter 4 integers separated by a space:
1 2 3 4
Your numbers in reverse order are:[D@1f96302

View Replies View Related

Writing A Pizza Program - Average Cost Of Order

Oct 9, 2014

I'm trying to write a program that will output the total number of large,medium,and small pizza along with the average cost of an order. I'm stuck on this error , "Else without if" on line 48 else ...medium.

import java.util.Scanner;
public class PizzaOrder
{
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
double cost,total, average;
String name,response,size,type;
int count,l,m,s;

[code]....

View Replies View Related

Extract Higher-order Bits Of Random Number In Order To Get Longer Period

Mar 1, 2014

One of the random number generators in Java extract the higher-order bits of the random number in order to get a longer period.

I'm not sure if I understand how this is done. Suppose that the random number r = 0000 1100 1000 1101. If we extract the 16 most significant bits from r; is the new number r = 0000 1100 or r = 0000 1100 0000 0000?

View Replies View Related

Program That Asks User For Integer And Prints Out All Its Factors In Increasing Order

Nov 18, 2014

Write a program that asks the user for an integer andthen prints out all its factors in increasing order. Use a class FactorGenerator with a constructor FactorGenerator(int numberToFactor) and methods nextFactor and hasMoreFactors. Supply a class FactorTester whose main methods reads a user input, constructs a FactorGenerator object and prints the factors.

Here is what I have so far for my main class and tester class

public class FactorGenerator
{
int factor;
int number;
int x;
FactorGenerator(int numberToFactor)
{
number = numberToFactor;
}

[Code]....

View Replies View Related

Binary Tree Post Order / Inorder And Pre-order Traversal

Jan 26, 2014

Any link to the accurate explanation of binary trees in java?

View Replies View Related

Keep Track Of Result Of Each Roll Using Array

Mar 8, 2014

The code I have below asks the user how many times you want to roll the dice. It rolls dice 1 and dice 2 randomly and gives the total. Now, I'm trying to keep track of the result of each roll using an array that is indexed by the sum of the roll of the two dice. Then I want to output my result in a table that shows each value (from 2 - 12)) and the number of times that value was rolled. I would like to do this preferably with the JTextArea class, but it doesn't have to be. I keep getting errors.The code below works for the dice rolling in the 1st paragraph. I took out all the bad code I was trying to use for the 2nd paragraph.

package Part2pack;
import java.util.Random;
import javax.swing.JOptionPane;
class Dice{
public static void main (String args[])
{
String input = " ";
int count = 0,dice1,dice2;

[code]....

View Replies View Related

Creates Two Die Objects And Roll Them Display The Values

May 4, 2014

I've written a die program, and i want the user to type any key in order to continue, how do i achieve this ?

I have already created a Die class, i just want to implement the main method now.

PHP Code:

package test;

/* This program demonstrates the use of a user-defined class

public class RollingDice {
// Creates two Die objects and rolls them display the values.
public static void main (String[] args) {
Die die1 = new Die();
System.out.println("Roll the die ")
}
} mh_sh_highlight_all('php');

What should i add after System.out.println, So that the user types (any key, or types "Enter" for example, for the die to roll). i dont want the die to roll by itself i Want the user to interact with the program in order for it to roll.

View Replies View Related

Roll Four Sided Die Between 100 And 1000 Times Depending On Input And Display Answer

Oct 29, 2014

I'm trying to get the program to roll a four sided die between 100 and 1000 times, depending on your input, and then displaying the answer.

public class Lab08
{
public static void main(String[] args)
{
int v1 =0, v2 = 0, v3 = 0, v4 = 0;
int n;
char response;
System.out.print("Enter number of rolls (100-1000): ");
 
[Code] ....

View Replies View Related

Program That Accept Words And Their Meanings Or Display List Of Words In Lexicographical Order

Apr 15, 2015

Write a menu driven program that either accepts words and their meanings, or displays the list of words in lexicographical order (i.e. as in a dictionary). When an entry is to be added to the dictionary you must first enter the word as one string, and then enter the meaning as separate string. Another requirement - from time to time words become obsolete. When this happens, such word must be removed from the dictionary.

Use the JOptionPane class to enter the information.

Use the concept of linked list to carryout this exercise. You will need at minimum the following classes:

- A WordMeaning class that hold the name of a word and its meaning.
- A WordMeaningNode class that creates the node of information and its link field.
- A WordList class that creates and maintain a linked list of words and their meanings.
- A Dictionary class that test your classes.

For the output, the program should produce two scrollable lists:

- The current list of words and their meanings.
- The list of the deleted words. You need not list the meanings, just the words.

So far, I have everything coded except for the remove method, and I am not sure how to code that. I coded the add method already, but now I don't know where to begin with the remove method in my WordList class. My classes are below.

WordMeaning Class:

public class WordMeaning {
String name;
String definition;
WordMeaning(String t, String d) {
name = t;
definition = d;

[Code] .....

View Replies View Related

Simulate Rolling Two Dice

Oct 18, 2014

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:

Sum 2 3 4 5 6 7 8 9 10 11 12
Total 33 49 93 103 127 159 150 124 85 49 28

This is my code:

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.

View Replies View Related

Using Loops For Dice Probability

Oct 5, 2014

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

Sum of dice Probability

20.0
20.0
30.0
30.0
40.0
40.0
50.0
50.0
650.0
650.0
70.0
70.0

Now I don't really understand the concept in the first place as the lesson was extremely uninformative, so I don't know what went wrong here.

View Replies View Related

Obtain Dice As Text Not Numbers

Oct 2, 2014

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.

View Replies View Related

Changing Number Of Sides On A Dice From 6 To 12

May 29, 2014

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:

package homeworkweek6;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

[code]...

Do I have to add more code somewhere further up in the program, or is there a line to replace these two lines to make it 12-sided?

View Replies View Related

Not Counting Total Of Dice Rolls

Jan 25, 2015

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;

[code]...

View Replies View Related

Do While Loop - Rolling Dice And Getting Scores To Add Up To 100

Aug 21, 2014

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;

[Code] ....

View Replies View Related

Random Dice Roller Game

Oct 23, 2014

So far I have

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.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved