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


ADVERTISEMENT

How To Assign Numbers Obtain From Modular Equation To Certain Position In Array

Apr 16, 2015

My biggest issues are as follows:

1) I'm trying to use a logarithm to determine the length of a user input number. I keep getting an error stating <> indetifier expected. I'm assuming this means that the program is not recognizing the function of a logarithm. I know that normally you can include that information in the method, but my teacher has stated specifically that each of these methods be called something else, as shown in the code.

2) I'm not quite sure I understand how to assign the numbers I obtain from the modular equation to a certain position in the array. As I'm asking the user to input any number these values can change so therefore I can't simply state that first number = this place.Here is my code:

import javax.swing.*;
import javax.*;
public class getSize
{
public static void main( String[] args )

[code]...

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

Servlets :: How To Obtain Contents Of Td

Mar 19, 2014

i have created a table in jsp, i want to obtain the contents of a td at the servlet.For example, here's one td of table:

<td align="center" title="tdun" id="cat"> <%= categoryname %> </td>

I want to get this value in my servlet .

View Replies View Related

Obtain Color From Borders

Oct 10, 2014

I'm doing this project where I need to make a persian carpet using recursive methods. I already have my recursive what I'm trying to implement is the use of color. My method BorderColor draws a square using a random color choose from an array.

public void Cuadrado(Graphics g){
Random color = new Random();
g.setColor(colors[color.nextInt(colors.length)]);
g.drawLine(left, top, right, top);
g.drawLine(left, top, left, bottom);

[Code] ....

What I'm trying to do is getting the color from 4 different corners in order to create a new one and make a recursive call. I already tried using the method getPixelColor from the Robot() object but I quit it because is a recursive method and it may cause trouble with the recursive stack. I created this method to create the new color and then call it in the PersianRug method, but I dont have a clue on how to obtain and implement the new colors.

public int newColor(int c,int c1,int c2,int c3, int a){
int c4=((c+c1+c2+c3)%13)*a;
return c4;
}

View Replies View Related

To Obtain Explanation On Singleton Implementation

Jan 11, 2014

I've found following code for Singleton Implementation from this forum, I am having a difficulty of understanding following,

1. When Singleton instance will be created, ( From which call ) ?

2. What feature of Static Inner class allow object to be singleton ?

3. How Inner Class implementation is thread safe ?

4. What will happen if variable "instance" mark as non-static, Will it still grantee singleton implementation ?

Java Code:

public class Singleton {
// Note private constructor
private Singleton() {}
private static class SingletonInner {
private final static Singleton instance = new Singleton();
}
public static Singleton getInstance() {
return SingletonInner.instance;
}
} mh_sh_highlight_all('java');

View Replies View Related

EJB / EE :: How To Obtain 2 Different SLSB By Two Successive Calls

Oct 4, 2014

I use jboss eap 6.2 under eclipse.I perform a tutorial on EJB and I want to show the difference between a stateless session bean and a statefull session bean. I want demonstrate that the first one keep its state (if it has one) but that 2 successive don't send back necessarily the same SLSB : it send back the SLSB that is ready in the pool. But I don't suceed in obtaining 2 different SLSB by 2 successive call. The system always send me back the same SLSB.

View Replies View Related

Obtain Server Specifications Based On Application

Jun 19, 2014

a new java executable file which does heavy processing (batch). Development hasn't really started yet and the design phase is just beginning. Now the client is asking us to give them the minimum server specs to be able to run our application..I'm thinking this can't be done without performance testing, which will be after development. Is there a better and faster way to be able to assess this?

View Replies View Related

How To Read Numbers And Names From A Text File

Mar 20, 2014

I have a text file containing numbers and names as shown in the example below:

61133128805241Albert Rosenberg
64763645543509Joel
79256337754219Michael Burton

I'm making a program that will read the file and put the numbers in a list of int arrays and names in another list of strings. In my program i created two classes. One will receive the numbers and the other will receive the names. But i only can read the numbers! How can I read everything and separate into two different lists?

try( BufferedReader br = new BufferedReader( new FileReader( jFileChooser1.getSelectedFile().getAbsolutePath() ) ) ) {
hist = new Historic();//Will recieve the array of numbers.
while( br.ready() ) {
int line[] = new int[ 7 ];

[Code] ...

View Replies View Related

Sorting A Text File With Strings And Numbers

Oct 16, 2014

how to sort my text file. So far I have been able to read the text file and print it back out, but I am unsure of how to go about sorting it. Must print the colors (in the order of the rainbow first) and if the colors are the same compare the size (bigger is more important)The values I have to sort are written as such in the text file:

blue 18
blue 10
red 27
yellow 4

public class Rainbow{
private String color;
private int size;
public Rainbow(String color, int size){
this.color = color;
this.size = size;

[code]....

I would know how to sort it if it was supposed to be alphabetical order or there were only numbers, but I can't seem to figure out how to sort it when there are strings and integers

View Replies View Related

How To Modify Text So That It Doesn't Contain Two Equal Numbers

May 3, 2014

I would like to create a program that takes some files and modifies them in this way: The files should contain text formatted in this way:

##############
#various comments#
##############
something{
identifier=1234
anotherIdentifier=1235
anotherOne=12345
//and so on...
}//I need only this
 
#Comments are sometimes made this way
 
somethingAgain{ 
#comments that explains what's below them
I:dentifier:something, I, do, not, need
#see ^that
A:notherIdentifier:boolean
//and so on..
}

And I have to make so that the numbers contained in something{} in all the files don't match. I could ask to make so that the input file is only one, and it is formatted this way:

identifier=1234
anotherIdentifier=1235
anotherOne=12345
//and so on...

but I don't know how to do the rest of the program... That's what I've done (the names of the classes, package etc. are in Italian and there's some useless code that NetBeans prevents me from deleting):

package confronto;
import java.awt.Color;
import java.io.*;
import javax.swing.*;
public class confrontoTesti extends javax.swing.JFrame {
 
[Code] ....

View Replies View Related

Counting The Frequency Of Numbers Inside A Text File

Apr 7, 2014

I have a source code here that counts the frequency of alphabetic characters and non-alphabetic characters (see the source code below).

import java.io.*;
 
public class letterfrequency {
public static void main (String [] args) throws IOException {
File file1 = new File ("letternumberfrequency.txt");
BufferedReader in = new BufferedReader (new FileReader (file1));
 
[Code] ....

But, let's just say that now I have the following characters in the text file, "letternumberfrequency.txt":
71 geese - 83 cars - 58 cows- 64 mooses- 100 ants- 69 bangles- 90 molehills - 87 noses

The numbers inside that text file would be considered as strings, am I right? But I want to extract the numbers so that I can also be able to count their frequency - not as individual digits but as whole numbers (that is how many "71", "83", "58", "64", etc. are there...). Would using "Double.parseDouble ()" work?

View Replies View Related

Extracting Numbers In Word Format From A String Of Text

Aug 7, 2014

I am trying to do is extract numbers that are in word format in a long String, i.e. a song, and return each of their numerical values, in order to add them all up. So I'd like to calculate the sum of all of the numbers in the text. This has to work for any piece of text and for all numbers up to a trillion.

So I broke the string down into tokens and stored them in a String []. And I divided up the possible numbers in word format into:

LARGEST: thousand, million, billion, trillion
HUNDRED: hundred
TENS: twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety
UNITS: one, two, three, four, five, six, seven, eight, nine
SPECIALS: ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen

I believe that these are the only words that it will need to recognize. I began reading the tokenized string from right to left and then when I came across a unit, special or tens as the first number I hit, I would then set it's numerical value and check if the word before was also a number and whether to add or multiply etc. i.e. First number hit is a two, if the number before is sixty, then I would just add it to sixty and check the word before that and so on.

However, when implementing it, it seems like an extremely long way around it. How I could implement this in a swifter manner? An example of it working would be:

"Nine Million rockets turned Three times and met Twenty Two Aliens", it would extract, Twenty Two as 2, then 20 = 22, then extract Three as 3, and then Nine Million as 1,000,000 x 9 = 9,000,000

9,000,000 + 22 + 3 = 9,000,025

View Replies View Related

Java Algorithm - Convert String Of Numbers Into Text

Feb 18, 2014

I need a Java algorithm that converts a string of numbers into text. It is related to how a phone keypad works where pressing 2 three times creates the letter "c" or pressing 4 one time creates the letter "g". For example a string of numbers "44335557075557777" should decode where 0 equates to a space.

View Replies View Related

Can Change Arraylist To Have Number Images Rather Than Normal Text Numbers

Apr 9, 2014

I was wondering if it would be possible if i can change the arraylist to have number images rather than NORMAL text numbers?

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

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

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

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

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

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

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

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