How To Shuffle Numbers Every New Game

Dec 15, 2014

How to shuffle the numbers every new game? Heres my the code.

package project;
import java.io.*;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
public class khoProject {

[Code] ....

View Replies


ADVERTISEMENT

How To Shuffle Array Using Random Numbers

Nov 10, 2014

For a project we have to "shuffle" items in an array using random numbers. We are supposed to generate random numbers and use those numbers to exchange array elements. But I am not sure what that means, "exchange array elements". Does that mean you generate 2 random numbers within the length of the array, and then switch the items at those locations in the array?

View Replies View Related

Bingo Game - How To Call 5 Numbers From Array

Aug 18, 2014

I am writing a Bingo program for a class and have reached a roadblock. How do I call 5 numbers from the array and where do I store them so I can populate them back into my JLabels on the Bingo card. I'm sure there are more complicated ways to do this, but I'd like to keep it simple so I actually understand the process. I understand that I will need to shuffle the numbers in the array before choosing them, but I also am not sure how to do that.

int [] BArray = {1,2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
for (int index = 0; index > 5; index++) {
}

View Replies View Related

Lottery Game Matching Numbers Error

Dec 11, 2014

import java.util.Scanner;
import java.util.Arrays;
public class LotteryTester {
public static void main(String[] args) { 
LotteryApplication lottery = new LotteryApplication();
int lotteryNumbersCount = lottery.getLotteryNumbers().length;
 
 [Code] ....

Everything works fine but when I run it the matching numbers tends to be off. For example I will type Enter in 1,1,1,1,1 for my 5 numbers. The lottery numbers will be 5,3,4,5,8 and it will say 1 number matched.

View Replies View Related

Off-by-one Error In Perfect Shuffle Method

Jan 29, 2015

I am supposed to create a method that simulates a perfect shuffle of a given array of integers. According to the assignmment, this is what a perfect shuffle is:

This procedure is called a perfect shuffle if the interleaving alternates between the two half-decks.Unfortunately, the perfect shuffle comes nowhere near generating all possible deck permutations.In fact, eight shuffles of a 52-card deck return the deck to its original state!Consider the following perfect shuffle algorithm that starts with an array named cards that contains 52 cards and creates an array named shuffled.

Initialize shuffled to contain 52 empty elements.
Set k to 0.
For j = 0 to 25,
− Copy cards[j] to shuffled[k];
− Set k to k+2.
Set k to 1.
For j = 26 to 51,
− Copy cards[j] to shuffled[k];
− Set k to k+2.

This approach moves the first half of cards to the even index positions of shuffled, and it moves the second half of cards to the odd index positions of shuffled.The above algorithm shuffles 52 cards. If an odd number of cards is shuffled, the array shuffled has one more even-indexed position than odd-indexed positions. Therefore, the first loop must copy one more card than the second loop does. This requires rounding up when calculating the index of the middle of the deck. In other words, in the first loop j must go up to (cards.length + 1) / 2, exclusive, and in the second loop j most begin at (cards.length + 1) / 2.

View Replies View Related

Guessing Game (numbers Between 1 And 100) - Getting Results To Give Correct Int

Feb 10, 2015

I've been working on a program where you can interact with the computer and play a guessing game of numbers between 1 and 100. It's mainly finished, I just need to add in my comments and stuff. My one problem about it that I cannot figure out is trying to get the results to give the correct int. At the end of the game, it's supposed to return the user information about how well they did like this:

Overall results:
total games = int
total guesses = int
guesses/game = double
best game = int

best game should give you the least amount of guesses you had during a particular round of the game. Here is what I have so far:

import java.util.*;
public class Guess {
public static final int MAX = 100;
public static void main(String[] args) {
intro(MAX);
Scanner console = new Scanner(System.in);
int tempBestGame = 0;

[Code] .....

View Replies View Related

Applets :: Display Images Of Playing Cards And Shuffle The Deck

Jul 28, 2014

"In this assignment you will use an applet to display images of playing cards. The applet should load a deck of 52 playing card images from the "images" folder that you downloaded. The applet should shuffle the deck (use a random number generator) and display the first 10 cards of the shuffled deck. Display the cards in two rows of five cards each."

That is my goal for this assignment. I've got my code compiling and I will post it below and I've got an html page but when I try to open it I get an error

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Random;
public class Assignment12 extends Applet {
Image card1;
Image card2;

[Code] ....

View Replies View Related

Random Shuffle Array Of Card Objects Which Does Function Of Deck

Oct 26, 2014

I have to random shuffle an array of Card Objects which does the funcion of a deck. Heres the code:

Java Code:

public void barajear(){
int j;
for (int i=0;i<52;i++){
j=Baraja.random(51);
if (this.mazo[j]==null){
this.mazo[j]=this.arreglo[i];
}else{
--i;
}
}
} mh_sh_highlight_all('java');

so bassically theres an array called "arreglo" which has the cards in order and the function "random" its an rng of numbers from 0 to 51.what i'm trying to do it's to take the cards from the ordenated array and put them randomly in the other but only if it's empty.(the array "mazo" has alredy been initialized with null).it worked at first, but now, after compiling succesfully i tried to run it and the cmd just...

View Replies View Related

Images Of Cards - Shuffle Deck With Random Number Generator And Display First 10

Aug 18, 2014

So I'm trying to make an applet that displays images of cards. The applet has a deck of 52 playing card images. It should shuffle the deck with a random number generator and display the first 10 cards of the shuffled deck.

With this code I have about 100 errors and I'm not sure what I'm doing wrong: I know I have to use arrays in order to ultimately display the images, but do I have to create Image objects for the Image [] cards array? I am getting many "class, interface, enum expected" errors as well as others.

import java.util.Random;
import java.awt.Image;
import java.applet.Applet;
import java.awt.Graphics;
public class unit12 extends Applet
{

[Code] .....

View Replies View Related

Opoly Game - Goal Of The Game Is To Reach Or Exceed Reward Value 1000

Mar 12, 2015

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.

View Replies View Related

Tic Tac Toe Game - Random Number Generator And Two Dimensional Arrays For Game Board

May 9, 2015

Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.

import java.util.Random;
import java.util.Scanner;
 public class TicTacToe {
 private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
 
[Code] ....

View Replies View Related

Long Type Output File - Print Prime Numbers Between Given Range Of Numbers

Aug 22, 2014

I tried to create file and write the output of my program in it in java when i use WriteLong then the file does not contain long value, how I create this file my program is to print prime numbers between 500000 to 10000000

public class primenumber {
public static void main(String[] args) {
long start = 5000000;
long end = 10000000;
System.out.println("List of prime numbers between " + start + " and " + end);
for (long i = start; i <= end; i++) {
if (isPrime(i)) {
System.out.println(i);

[Code] ....

View Replies View Related

Generate 100 Numbers Using Arrays - Sort Even Numbers Into Separate Array And Display Both

Apr 24, 2014

I've just written a program that generates 100 numbers that range from 0 ~ 25 using arrays, the program calls another method that sorts the even numbers into a separate array and returns the array. I need it to display both arrays, however, when I run my program, the numbers of both arrays are mixed together, and I'm not sure how to separate them.

[ public class Array1
{
public static void main(String[] args)
{
int array [ ] = new int[100];
for (int i = 0; i < array.length; i++)
{
array[i] = (int) (Math.random() * 26);

[Code] .....

View Replies View Related

Print 2 Lists - 20 Random Numbers And Another List Without Duplicate Numbers

Feb 1, 2015

I'm trying to make a program that generates 20 random integers between 1 and 20 and then prints the list of random numbers to the screen. After that, I want to print a different list to screen with the same numbers from the first list only skipping any number that has been already printed to the screen. So two lists are printed to the screen. The first one has 20 random numbers. The second one has those same 20 numbers but only prints the numbers in the first list that aren't duplicated. So if m

y list of 20 random integers contains three 2s and two 14s, only one 14 and one 2 is printed to the second list. Currently, my code generates 20 numbers from 1 to 20 and stores those numbers in an array but I don't know how to print solve the second part of my problem. I don't know how to print the s different list only without duplicate numbers. As a result, my output is nothing because it doesn't print any number from the first list as oppose to skipping only duplicate one.

public void randomNum(){
System.out.println("Twenty random integers: ");
int max = 20; // max value for range
int min = 1; // min value for range
Random rand = new Random();
int[] all = new int[20];

[Code] ....

View Replies View Related

User To Enter 10 Numbers And At The End Prints Out Distinct And Non-repeated Numbers

Nov 23, 2014

I have to make a program that prompts the user to enter 10 numbers and at the end it prints out the distinct numbers and then the other numbers that weren't repeated...

I have the part where it prints out the distinct numbers but I stuck on how to make it print out the other numbers that didn't repeat...

import javax.swing.JOptionPane;
public class DistinctNumbers {
public static void main(String[] args) { 
String getInput;
int input;
int[] numbers = new int[10];

[Code] ....

View Replies View Related

Generate Two Arrays - One With All Positive Numbers And Another With Negative Numbers

Mar 10, 2015

Create an integer array with 10 numbers, initialize the array to make sure there are both positive and negative integers. Write a program to generate two arrays out of the original array, one array with all positive numbers and another one with all negative numbers. Print out the number of elements and the detailed elements in each array.

public class problem3 {
public static void main(String[]args){
int[] numbers = {1, 2, 3, 4, 5, -1, -2, -3, -4, -5};
for (int i = 0; i<numbers.length;){
if(i>0){
System.out.println(numbers);
}
else
System.out.println(numbers);
}
}
}

View Replies View Related

Generate Random Numbers Without Certain Numbers In Range

Jul 31, 2014

I tried out doing number (generated randomly) != (another number) but that does not work. If I for example want a number between 1 and 10, but I do not want the number 5, what can I do in order to make this happen?

View Replies View Related

List All Prime Numbers Between Two Entered Numbers

Oct 17, 2014

Program is to list all prime numbers between two entered numbers.

import java.util.Scanner;
public class question6 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter lower int:");
int x = input.nextInt();

[Code] .....

View Replies View Related

Guessing Game - How To Reset Random Number When User Reset Game

Oct 2, 2014

I tried this program, its guessing game. Where program decide 1 number and user will guess number. I am getting 1 problem. When user want to play game again.the random number remain same. So where i can put reset random in code..? And 1 more question if I want to write driver code for this. What should i transfer to driver code.

import java.util.Random;
import java.util.Scanner;
public class GuessGame {
public static void main(String args[])
{
String choice="y";

[Code] ......

View Replies View Related

Moving A Map In A Game

Jul 22, 2014

I've been at this for a while and I would like to make the Camera in my game follow the player and I know the way to do this would be to move the map and not the player. How would I do this if my map is rendered from a text file using for loops. Here is my code for the map.

package Game;
import java.awt.Graphics;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Map {

[Code] .....

View Replies View Related

Getting TIE In Connect 4 Game?

Oct 20, 2014

I have compiled and coded the whole thing, but the TIE function when no one wins, isn't popping up. I'm not sure why but here is my code;

import java.applet.AudioClip;
import java.awt.*;
import javax.imageio.ImageIO;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;

[code]....

The TIE doesn't pop up, that is all the errors i have, though there is no error messages.

View Replies View Related

How To Add A Scorekeeper For Game

Apr 3, 2014

I am creating a simple AirHockey game in Eclipse Java Jframe. I was just wondering how it is i add a score keeper to my game. for example if player 1 scores a goal 1 is added onto there score at the top.

View Replies View Related

Tic Tac Toe Game Using While Statements

Oct 23, 2014

import java.util.Scanner;
public class TicTacToe {
public static void main(String[] args) {
//Create scanner
Scanner in = new Scanner(System.in);
//Declare variables to hold the board

[Code] ....

I need to create a while statement for random computer moves.

View Replies View Related

Tic Tac Toe Game Based On GUI

Apr 26, 2014

My instructor told me to make game from java but based on GUI. And I thought about it, I want to make Tic Tac Toe (X-O) game.

View Replies View Related

KeyBindings For A Game

Jan 26, 2014

I'm making a game which lets the player move around with arrow keys, but my KeyListeners are working less-than-satisfactorily. I googled this and I found that I should use KeyBindings.

1) Right now I have booleans for each key used in the game. When a key is pressed, the boolean is set to true, and set to false when it is released. In the ActionListener for the Timer I have, I then check if each is pressed or not, and do the corresponding action. I do this so that movement is smooth.If I was to use KeyBindings, would I use the same technique, or would I just do the action in their Action?

2) How do I do it? From the example I thought was most useful, this is my guess: (this code would be in a JPanel)

Java Code:

this.getInputMap().put( KeyStroke.getKeyStroke( "ENTER" ) , "doEnterAction" );
this.getActionMap().put( "doEnterAction" , EnterAction );
static class EnterAction extends AbstractAction
{
public void actionPerformed( ActionEvent tf )
{
enterKeyIsPressed=true; //If using this method, I would also have a separate InputMapping, ActionMapping,

[code]....

View Replies View Related

Tic Tac Toe Game 2D Array

Apr 13, 2014

I know a lot of people taking beginning java courses have posted questions about creating a tic tac toe game, but here is another one. Below is my code. I can't seem to get the X's and O's to show up on the board or to determine a winner.

import java.util.*;
public class Trial3
{
public static char turn;
public static int count;
public static void main(String[]args)
{
Scanner input=new Scanner(System.in);
char[][]b=new char[3][3];
boolean flag=false;
count=0;

[code]....

View Replies View Related







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