DiceStatistics - Represent Pair Of Dice And Totals Of Their Rolls
Apr 19, 2014
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?
View Replies
ADVERTISEMENT
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
Mar 14, 2015
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();
[Code] ....
View Replies
View Related
Apr 15, 2014
I need to work on this "Dice" program. I've done it twice already. I've also been pouring over examples on here and elsewhere online, but none of them exactly match what I'm doing, as they all say "Pair of Dice".Mine says: "Create a class called Dice to represent a SINGLE cube". It should have a method called roll() that randomly selects a number from 1-6 for the value of the dice."
It has to use java.util.random, not math.java, and it has to have numberShowing:int, roll():int, and main() all in it.The last part reads "Create a test main method for the Dice class that creates a dice and rolls it many times. Can you keep track of how many times a number comes up? Describe how or implement it in the program." I have started at this computer for hours, and read as much info as I can.
View Replies
View Related
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
Mar 29, 2015
I want to convert this following piece of c++ code into java...but i cannot find suitable substitute for vector pair...what shall i do?
#include <cmath>
#include <cstdio>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
bool compare_polar (int x1, int y1, int x2, int y2) { // if p2 > p1 return true
[Code] .....
View Replies
View Related
May 8, 2014
What are the x- and y-coordinates of the Points referred to as p1, p2, and p3 after the following code executes? Give your answer as an x-y pair such as (0, 0). Recall that Points and other objects use reference semantics.
PHP Code:
Point p1 = new Point();
p1.x = 17;
p1.y = 9;
Point p2 = new Point();
p2.x = 4;
p2.y = -1;
Point p3 = p2;
p1.translate(3, 1);
p2.x = 50;
p3.translate(-4, 5); mh_sh_highlight_all('php');
P1:
P2:
P3:
My guesses were: P1:(20,10) //Correct
P2:(50,-1) //Incorrect
P3:(0,4) //Incorrect
View Replies
View Related
Sep 27, 2013
I have been having difficulty with the weeks concepts in my online Java class, the program is to be as followed:
For this exercise you will implement a class called Pair, that represents a pair of two numbers.The Pair class should include the following constructor and methods:
CONSTRUCTORS
public Pair(double num1, double num2) -- Creates an object that represents a pair of double values
METHODS
public double getAverage() -- Returns the average value of the two numbers
public double getDistance() -- Returns the absolute vale of the distance between the two numbers
public double getMaximum() -- Returns the maximum value of the two numbers
public double getMinimum() -- Returns the minimum vale of the two numbers
Write a class called PairTest that tests your Pair implementation. The PairTest should prompt the user for the two values, create a Pair object with the values and then print the average, distance, maximum, and minimum of the pair. The input / output should look like the following:
Enter the first number: 5.5
Enter the second number: 3.0
Average: 4.25
Distance: 2.5
Maximum: 5.5
Minimum: 3.0
NOTE: For this exercise, your solution should not use any conditional statements. Instead you should use the methods provided by thejava.util.Math.
So far I have:
import java.lang.Math;
import java.util.Scanner;
public class Main
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
{
System.out.println("Please enter a value for the first number");
[Code] ....
View Replies
View Related
Apr 5, 2015
I am making a java program that translates English into Pirate. I need working with the Word Pair class. I'm not sure what needs to be passed to the default constructor. And how to do the method that will take the words and pair them. here is my code and the dictionary file
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class PirateTranslator {
public static void main(String[] args)
[Code] .....
View Replies
View Related
Apr 6, 2014
I'm getting an "identifier expected" error for the following code for comparing 2 wallets and printing each pair of banknotes. Here's the code.
public void printBankNotePairs(Wallet other)
{
StringBuffer myBuffer = new StringBuffer("Pairs: ");
for(int i = 0; i < count; i++)
{
for(int j = 0 + i; j < other.length; j++)
[Code] .....
View Replies
View Related
Nov 5, 2014
So I have an array which holds 19 elements, each element represents a value of 'income'. I'm trying to code the graph so that each bar will represent the value of each element of the array (income). I have been given the code ' for (int Bar = 0; Bar < array of values.length; bar++);' however i'm unsure if this is how to do it, or what to add to this code to make it work.
View Replies
View Related
Apr 12, 2015
how to split and then represent the splitted sentence.Suppose I have:
Java Code:
String sentence = "I Love my mother <=> I Love my father";
String[] array = sentence.split("->"); mh_sh_highlight_all('java');
But how can I get now the lefthandside String values which is "I love my mother" and righthandside "I love my father"? I tried smth like:
Java Code:
String[] leftHandSide = array[0].split(" ");
String[] rightHandSide = array[1].split(" "); mh_sh_highlight_all('java');
But it's not working - getting error.
View Replies
View Related
Jan 8, 2015
I was told to design a class named Rectangle to represent a rectangle.The class contains:
■ Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height.
■ A no-arg constructor that creates a default rectangle.
■ A constructor that creates a rectangle with the specified width and height.
■ A method named getArea() that returns the area of this rectangle.
■ A method named getPerimeter() that returns the perimeter.
Draw the UML diagram for the class and then implement the class. Write a test program that creates two Rectangle objects one with width 4 and height 40 and the other with width 3.5 and height 35.9. Display the width, height, area,and perimeter of each rectangle in this order.Here is my code for the Rectangle Class:
class Rectangle
{
double width;
double height;
public Rectangle() {
width = 1;
height = 1;
[code]....
The error that I am given when I compile the driver is as follows:constructor Rectangle in class Rectangle cannot be applied to given types; required: no arguments; found:int,int; reason: actual and formal argument lists differ in length.
View Replies
View Related
Jul 16, 2014
2. Declare a class called Quadrilateral that can be used to represent a quadrilateral. What instance variables are required? This class should include the following methods:
• Accessor and mutator methods. Notice that negative and zero lengths should not be accepted.
• A method called isParallelogram that returns a Boolean value indicating if the quadrilateral is a parallelogram.
• A method called isRectangle that indicates if the quadrilateral is a rectangle. This method should invoke the method isParallelogram and return a Boolean value.
• A method called isSquare that returns the Boolean value “true” if the quadrilateral is a square. This method should invoke the method isRectangle and return a Boolean value. URL...
import java.awt.Point;
public class Quadrilateral{
private Point p1, p2, p3, p4;
public Quadrilateral (Point p1, Point p2, Point p3, Point p4) {
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
this.p4 = p4;
}
}
that is all i got, my professor has never mentioned on anything about quadrilateral,and i have 0 knowledge about this.
View Replies
View Related
Feb 12, 2014
I am creating a deck of 52 cards each with their rank(1 2 3...King, Ace) and suit(Clubs... Spades).
I want to be able to print out value of each card after creating them such as - 2 of CLUBS and so on. I am able to do that now. Only problem is, when it comes to the picture cards, I am representing them with numbers 11(Jack), 12(Queen) 13(King) and 14(Ace). I can't quite get around to changing the numbers to be represented as the actual words (King and so on).
I imagine that I should store the jack,queen,king,ace values in an enum too and call it in my loop but can't quite get it. Should I have like a 3rd for loop in my following codes to make it work?
Java Code:
//My main method. The Card class follows below
public static void main(String[] args) {
Card[] cards = new Card[52];
int i = 0;
for (Card.Suits suit : Card.Suits.values()) {
for (int y = 2; y < 15; y++) {
cards[i] = new Card(y, suit.name());
i++;
[Code] .....
View Replies
View Related
May 3, 2014
I am working on my project that uses elgamal elliptic curve. I know when the elgamal ec encrypt by following steps
Represent the message m as a point M in E(Fp).
Select k ∈R [1,n−1].
Compute C1 = kP.
Compute C2 = M +kQ.
Return(C1,C2).
Where Q is the intended recipient’s public key, P is base point. My qusetion at number one.How represent m as a point. Is point represent one character or represent group of characters. also I need code by java done this issue like Koblitz Encoding Method for ECC
View Replies
View Related
Aug 2, 2014
To simulate it, the program will generate a random number between 0 and 19, which represents the location in the array (i.e. index number). Then, the 3 numbers to the left and right of this location should be reset to the value 0. If there isn't 3 numbers to the left and right you may assume a lesser number depending on the boundaries of the array.
How to reset the numbers to 0 in the final array ?
View Replies
View Related
Jul 29, 2014
I am trying to run a class with a client code and I get the following error
The method add(TimeSpan) is undefined for the type TEST
Why i get this error?
package timespan;
// Represents a time span of hours and minutes elapsed.
// Class invariant: minutes < 60
public class TimeSpan {
private int hours;
private int minutes;
[Code] ....
View Replies
View Related
May 22, 2014
We are doing a visualisation tool for point cloud research project. We use 3d sphere to represent each single point and when we have large number of points to display (~40,000), the rotation becomes very lagging.
What we have tried:
set JVM flag -Djavafx.animation.fullspeed=true, this worked a bit, but not significant.set JVM flag -Djavafx.autoproxy.disable=true, this did not work.
set Cache to true and CacheHint to Cache.SPEED, this did not make much difference.create another thread to do the rotation, and sync back after calculation, this did not work neither.
View Replies
View Related
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
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
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
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
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
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
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