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++) {
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): ");
I'm new to Java. I have a problem with this code, wherein you have to count how many times you borrow in order to do subtraction.
For example: x = 312; y = 34;
The output should be: 2 because you have borrowed 2 times in subtraction.
My problem is like this, whenever I input x=12, y=2, the output is 1, also, when x = 12, y = 1. It should be 0.
Here's my code:
import java.util.Scanner; public class BorrowOut{ public static void main (String [] args){ Scanner in = new Scanner (System.in); int x; int y; int i = 0; int j = 0;
I have problems getting the right number of times for each number of the array. Here is my code:
public static void main(String[] args) { int[] a = { 3, 13, 5, 9, 13, 6, 9, 13, 2, 3 }; int num = 3; int count = numbers(a, num); for (int i = 0; i < a.length; i++) {
Write a program using a while-loop (and a for-loop) that asks the user to enter a string, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. (So, you will have two separate program codes, one using a while-loop and the other one using a for-loop.)
Example: Enter a string: "Hello, JAVA is my favorite programming language." Enter a character: e The number of times the specified character appears in the string: 3
I don't even know where to begin I've only got this
import java.util.Scanner; public class letterCounter { public static void main(String [] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter a string"); String myString = sc.nextLine(); System.out.println("Enter a letter"); String letter = sc.nextLine(); } }
I am trying to flip a coin 1000 times and make the driver class count the number of times a head and tails appear. However, I am having some trouble trying to figure out the error:
package Week5; import java.util.Random; public class Coin { private int heads; private int tails; private int face;
[Code] ....
I was able to print out the generated numbers, but java will print either heads or tails a thousand times and count that as 1000 and nil for the other probability...
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();
I have made a basic math game that asks you questions and tells you if you have answered them correctly or incorrectly. The game runs great! The thing is that it asks you a question one time and after you answer you have to run the program again. I want to get the program to ask ten questions. After that I want to figure out a scoring system for it but the first step is to get it to ask my ten questions. Here is my code.
package pkgnew; import java.util.Scanner; import java.util.Random; public class New { public static void main(String args[]) {
Ii am trying run a do while loop on java a specific amount of times for example if i were to type in "Enter number of years" and enter 4. i need the loop to execute 4 times or if i said 6 times then i would be 6. the program i have repeats it and takes it back to reentering "Enter number of years" i need it to execute by its self x amount of times. here is what i have so far
System.out.println("Enter the number of years: "); years = keyboard.nextInt(); rainfall = generator.nextInt(10) + 1; System.out.println("Year " + "rainfall amounts were");; for (int months = 1; months <= 12; months++)
I am developing a java swing application. In which i want to set a different text to a label in same program ( in single JFrame). I dont want to use another JFrame instead i want to use setText method of java and set different text to a label at different intervals of time according to my need.
I am using java 1.7 sdk and pupy linux as OS. Below i am giving source code.
What i am doing is in constructor of class i am setting an image to JFrame and setting text "Welcom...". And when user clicks on this JFrame a method is called which will clear the text "Welcome.." and sets new text to another label "Enter...." and from there another method is called and it clears label "Enter..." and sets a text "Plzz wait..". and yet there are more methods, i havnt provided here.
But what is happening is it shows welcome text and then directly Plzz wait..
Its not showing text Enter... because control is finished after last method gets executed.
My concern is i want to show all the setText (my messages) in a sequence. Without using another JFrame. There is no any user input other than user will click on first welcome page.
public class BackgroundFrame extends javax.swing.JFrame {
My goal here is to create a program that will deny access to the browsers during certain times of the day. The research that I have done makes this out to be near impossible (using signal handlers in java). where to start, if its possible, or anything else im missing. (System is windows 7).
I need to write a JAVA program and algorithm that writes the numbers from 1 to 1000. Then I ned to write another one that writes the numbers from 1 to 1000, but 5 by 5. ( example 5,10,15,20,25,30)....
I am very new to programming. This is for a college assignment. It says in the brief of the assignment that we will need to convert Math.random to output a random number between 1-1000. How can I do this?
import java.util.Scanner; public class main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int number; System.out.println("Input a number");
[code]....
What i want to do is that if the number is greater than 50 to count until 100. else if the number is less than fifty to count for example from 36 to zero.
public static void main(String[] args) throws FileNotFoundException, IOException{ // TODO code application logic here FileReader fr = new FileReader("gautam.txt"); BufferedReader br = new BufferedReader(fr); int line = 0; int word = 0; int character = 0; String s; while((s=br.readLine())!=null)
I wrote a program to read a .txt file and return how many times a, e, s, and t occur in the .txt file. I am getting an error that I do not know how to fix. It says Error: FileNotFoundException cannot be resolved to a type...
import java.util.Scanner; import java.io.File; import java.io.IOException; import java.io.BufferedReader; public class Count { public static void main (String[] args) throws FileNotFoundException { String phrase; // a string of characters
I have an array with the following characters {'E', 'L','E','P','H','A','N','T','P','O'}
now, I need an array that will store the first array such that only the occurence occurs e.g {'E','L','P','H','A','N','T','O'} Notice that the characters 'E' and 'P' occur twice and as a result were not repeated the second time in the new array.
How would one go about this using the counting elements technique?
I tried this but not sure how to use the counting elements technique.
char [] arr = new char{'E', 'L','E','P','H','A','N','T','P','O'}; char[] bucket = new char[(arr[0] * arr.length)]; for (int i = 0; i < len; i++) bucket[arr[i]]++;
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; }
/** * 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.
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;
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 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.
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.
Opoly works this way: The board is a circular track of variable length (the user determines the length when the game app runs). There is only one player, who begins the game at position 0.
Thus, if the board length is 20, then the board locations start at position 0 and end at position 19. The player starts with a reward of 100, and the goal of the game is to reach or exceed reward value 1000. When this reward value is reached or exceeded, the game is over. When the game ends, your program should report the number of turns the player has taken, and the final reward amount attained.
In Opoly the game piece advances via a spinner - a device that takes on one of the values 1, 2, 3, 4, 5 at random, with each of the five spin values equally likely.
Although the board is circular, you should draw the state of the board as a single "line", using an 'o' to represent the current player position, and * represent all other positions. Thus if the board size is 10, then this board drawing:
**o******
means that the player is at location 2 on the board.
Here are the other Opoly game rules:
If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.
If you land on the final board cell, you must go back 3 spaces. Thus if the board size is 20, the last position is position 19, and if you land there, you should go back to position 16. (If the position of the last cell is evenly divisible by 7, no extra points are added, but if the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE added).
If you make it all the way around the board, you get 100 points. Note that if you land exactly on location 0, you first receive 100 extra points (for making it all the around), and then your score is doubled, since 0 is evenly divisible by 7,
Every tenth move (that is, every tenth spin of the spinner, move numbers 10,20,30,... etc.), reduces the reward by 50 points. This penalty is applied up front, as soon as the 10th or 20th or 30th move is made, even if other actions at that instant also apply. Notice that with this rule it's possible for the reward amount to become negative.
Here is the driver class for the game:
import java.util.*; public class OpolyDriver{ public static void main(String[] args){ System.out.println("Enter an int > 3 - the size of the board"); Scanner s = new Scanner(System.in); int boardSize = s.nextInt();
[Code] ....
heres the methods:
REQUIRED CODE STRUCTURE: Your Opoly class must include the following methods (in addition to the Opoly constructor) and must implement the method calls as specified:
playGame - The top-level method that controls the game. No return value, no parameters. Must call drawBoard, displayReport, spinAndMove, isGameOver.
spinAndMove - spins the spinner and then advances the piece according to the rules of the game. No return value, no parameters. Must call spin and move.
spin - generates an integer value from 1 to 5 at random- all equally likely. Returns an integer, no parameters.
move - advances the piece according to the rules of the game. No return value, takes an integer parameter that is a value from 1 to 5.
isGameOver - checks if game termination condition has been met. Returns true if game is over, false otherwise. No parameters.
drawBoard - draws the board using *'s and an o to mark the current board position. Following each board display you should also report the current reward. No return value, no parameters.
displayReport - reports the end of the game, and gives the number of rounds of play, and the final reward. No return value, no parameters.