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
ADVERTISEMENT
Nov 23, 2014
I am writing a java application that will function as a lottery game, using arrays it prompts the user to enter 5 digits and matches them against the random lottery numbers generated.
import java.util.Random;
import java.util.Scanner;
public class App {
public static void main(String[] args) {
int NUM_DIGITS = 5;
[Code] ....
View Replies
View Related
Sep 6, 2014
I wrote the following code for a lottery game. The problem comes when I run it. If one number of a 3 digit number matches, it's supposed to print "you win 1000" But regardless if a number matches or not, it says "sorry, no matches" ...
import java.util.Scanner;
public class Lottery {
public static void main(String[] args){
//generate lottery number
int lottery = (int)(Math.random() * 1000);
//Prompt the user to enter numbers
Scanner input = new Scanner (System.in);
System.out.print("Enter your numbers (3 digits): ");
int guess = input.nextInt();
[Code] .....
View Replies
View Related
Oct 29, 2014
I have problem with sorting my numbers from smallest to biggest and i need to not have repeating numbers, I am stuck. I tried using Arrays.sorts(lottery) but didn't work. and i don't know to but make the numbers not repeat in the same line.
package lottonumbers;
public class LottoNumbers {
public static void main(String[] args) {
int[] lottery = new int[6];
for (int numoftimes=0;numoftimes<5;numoftimes++){
[Code] ....
View Replies
View Related
Apr 14, 2015
I'm working on a Java matching game and I'm having a hard time wrapping my mind around it. What I'm having trouble with is how exactly to create an array so that my squares have random values. Then how do I get it to reveal and compare those values by clicking on two of them? Here is what I have so far:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
[code]....
View Replies
View Related
Jun 30, 2014
Making a memory game where you click a square it turns over an image and you match the two pretty simple. My issue is my images are not displaying and I am not sure why everything looks correct to me.
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.Random;
public class MemoryApp extends JFrame {
static String Pics[] = {"beaver.JPG", "dawgs.jfif",
[Code] ....
View Replies
View Related
Feb 13, 2015
"A common memory matching game played by young children is to start with a deck of cards that contain identical pairs. For example, given six cards in the deck, two might be labeled
1, two might be labeled
2 and two might be labeled
3. The cards are shuffled and placed face down on the table.
The player then selects two cards that are face down, turns them face up, and if they match they are left face up. If the two cards do not match they are returned to their original position face down. The game continues in this fashion until all cards are face up.Write a program that plays the memory matching game. Use sixteen cards that are laid out in a 4x4 square and are labeled with pairs of numbers from 1 to 8. Your program should allow the player to specify the cards that she would like to select through a coordinate system.For example in the following layout:
1 2 3 4
--------------------
1 | 8 * * *
2 | * * * *
3 | * 8 * *
4 | * * * *
All of the cards are face down except for the pair 8 which has been located at coordinates (1,1) and (2,3). To hide the cards that have been temporarily placed face up, output a large number of newlines to force the old board off the screen.Use 2D array for the arrangement of cards and another 2D array that indicates if a card is face up or face down.Or, a more elegant solution is to create a single 2D array where each element is an object that stores both the cards value and face.Write a function that shuffles the cards in the array by repeatedly selecting two cards at random and swapping them.
Note:To generate a random number x, where 0<= x <1, use x=Math.random();.For example, multiplying y six and converting to an integer results in an integer that is from 0 to 5."I have been thinking about the algorithm and design of the question for a few hours.
View Replies
View Related
Jun 4, 2014
I want my function to return an array, with the array holding just the values of data that appear in good.
This is what should be returned:
{3, 5, 3, 2, 3, 3}
What is currently being returned:
{0, 3, 5, 3}
I didn't want to miss any numbers, so I decided to iterate through j for the "good" array, and then just i for the one that I was looking for matching numbers. Perhaps part of the problem is that if the condition is met, it goes to the next iteration of the loop. I'm not sure.
public class Arrays2 {
public static void main(String args[]){
int [] data = {8, 3, 5, 3, 7, 2, 8, 3, 3 };
int [] good = {5, 2, 3, 2};
int [] result = f2(data, good);
for (int i = 0; i < result.length; i++){
[Code] ....
View Replies
View Related
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
View Related
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
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
Jul 25, 2014
I have tried changing the bounds of the arrays but I still don't see where the exception is occurring or how to resolve this issue. Am I missing something blatantly obvious? Below are the two class files for the lottery application that I've been working on for a school assignment.
package com.lottery.test;
import com.lottery.Alarcon.*;
import java.util.Scanner;
public class PlayLottery {
public static void main(String [] args){
System.out.println("CIS-132. Lab 8. Problem #9 - Lottery. Faber Alarcon.");
Lottery lottery = new Lottery();
[Code] ....
I forgot to post the error message I was getting, here it is.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at com.lottery.Alarcon.Lottery.compareNumbers(Lottery.java:26)
at com.lottery.test.PlayLottery.main(PlayLottery.java:27)
Java Result: 1
View Replies
View Related
Jun 8, 2014
I'm trying to make a simple battleship game, but when I make a ship with the addShip method (it is suppoused to initialize the board with the numbers 1,2,3 or 4 depending on the ship type, at the given coordinates) it dosen't initialize the field with any numbers, although the method returns true. The place the ship is suppoused to be made stays initialized with ".",
package battleship;
public class Sea {
private int width;
private int height;
private String[][] field;
[code].....
View Replies
View Related
Oct 13, 2014
/**
* In this program, use for and while loops with calculations to get the lottery odds.
*/
import java.util.Scanner;
import java.util.Random;
public class Lottery
{
public static void main (String []args)
[Code] .....
I need getting my numbers matching. When, I run the program each time no matter what number it keeps saying sorry no matches. However, I do need the program to have matches.
View Replies
View Related
Jun 4, 2014
I can't figure out this problem that I'm having in my Pong game. It's compiling fine, except when I run it, it gives me an overflow error.
Here's the code:
// Pong
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.Graphics;
public class Pong extends JFrame {
private static final int WIDTH = 400;
private static final int HEIGHT = 400;
[Code] .....
Here's the error:
java.lang.StackOverflowError
at sun.awt.AppContext.get(AppContext.java:604)
at com.sun.java.swing.SwingUtilities3.getDelegateRepa intManager(SwingUtilities3.java:120)
at javax.swing.RepaintManager.getDelegate(RepaintMana ger.java:1625)
at javax.swing.RepaintManager.addDirtyRegion(RepaintM anager.java:445)
The error keeps going for a lot of more lines.
The line that gets highlighted is the first bracket of the Pong constructor.
View Replies
View Related
May 8, 2014
So I am creating a game in Java, the game works fine when I run it in Eclipse but when I export it it does not draw anything on the screen.
I added a try and catch for nullpointerexceptions but the game does not throw any nullpointerexceptions.
What is the problem?
The game seems to be finding all the images & resources since it does not throw any NullPointerExceptions...
View Replies
View Related
Jan 2, 2015
I'm trying to fix this logic error in my slot machine game where no matter what slot combo comes up, it says you have won $10 and proceeds to add that amount to the balance and subtract the bet amount to the balance, even though it is not a winning combo! I've been trying to solve that and when doing so, I commented out Slot1.randNum1 == 0, Slot2.randNum2 ==0, and Slot3.randNum3 ==0 and anything relating to see if that was the problem, and it seemed like it was, because after that, the logic error described above was gone, but in doing so, the loss/win counter didn't increment, nor did the program pick up on the winning combos. However, I do not know why commenting out anything relating to randNum ==0 would cause that.
Here is the code for the processing (as you can see, some parts are commented in attempt to fix the logic error, but right now the code below is for the logic error that keeps on telling that the user has won):
public void askData ()
{
title ();
int betAmount;
while (true)
{
try
{
c.setCursor (3, 1);
[code]....
View Replies
View Related
Nov 5, 2014
package calculator;
public class operations {
int a = 5;
int b = 10;
public void add(int a,int b)
{
int c = a+b;
System.out.println(c);
}
}
I am not getting output to this question though it runs.
View Replies
View Related
Nov 29, 2014
I'm having some difficulty getting this GUI dice game to compile. I'm using javac and notepad++ for this and I'm getting the following errors:
DiceGame.java:34: error: cannot find symbol
die2label = new JLabel();
^
symbol: variable die2label
location: class DiceGame
[Code] ....
4 errors
My code is as follows:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
public class DiceGame extends JFrame
[Code] ....
I'm sure the problem is something trivial, but I guess that's all part of the learning process that I have to go through.
View Replies
View Related
Apr 23, 2015
I wrote a program that would play a game of Hangman. It plays the game but it keeps on bringing up a exception error. This is my class code
import java.util.ArrayList;
class Assignment2Q4
{
private final ArrayList<Character> guessList = new ArrayList<>();
private final char[] charArray;
private final String secretWord;
private int guesses;
[Code] ....
This is the output that is given:
Enter the secret word:
pizza
Guess a letter:
d
?????
Guess a letter:
[Code] .....
Also when I guess the first letter of the word correctly it stops the program without going further on with the guessing.
Like for ex. P????
View Replies
View Related
Sep 25, 2014
Write a Java program that randomly generates a five-digit lottery number and prompts the user to enter a five-digit number. Each digit in the number is in the range between 0~9. The program should determine which prize the user wins according to the following rule:
• The user wins the first prize if the user input matches all five digits in the lottery number in exact order.
• The user wins the second prize if the user input matches any four digits in the lottery number in exact positions.
• The user wins the third prize if the user input matches any three digits in the lottery number in its exact position.
• The user wins the fourth prize if the user input matches any two digits in the lottery number in its exact position.
• The user wins the fifth prize if the user input matches any one digit in the lottery number in its exact position.
and here is my code. I cant get it to print the right statements.
import java.util.Scanner;
import java.util.Random;
class Hw5 {
static int getPrize(int g1, int g2, int g3, int g4, int g5,
int u1, int u2, int u3, int u4, int u5) {
//code for determining the prize comparing (g1, g2, g3, g4, g5) to (u1, u2, u3, u4, u5)
if (u1 == g1 && u2 == g2 && u3 == g3 && u4 == g4 && u5 == g5)
[code]....
View Replies
View Related
Jan 25, 2015
I'm trying to put together a method that formats telelphone numbers, but there's a part of my code that not working. If I enter (305)912-5458 into the variable phoneNumb I get an index is out of range error. I added a lot of system out messages so that I can try to get an idea of why the code was crashing.
public static void main(String[] args) {
int intBegin = 0;
int intEnd = 1;
int length;
String charact;
StringBuilder numbuilder = new StringBuilder();
[Code] .....
The error message I'm getting is:
run:
The length is 13
intBegin is at 0
intEnd is at 1
index is at 0
Charcter ( was not inserted
[Code] ....
View Replies
View Related
Nov 27, 2014
I need to write a program that checks whether a Java source-code file has correct pairs of grouping symbols and the program must implement the Stack<E> class to solve this problem.
Here is the file:
[a({b,c}x{d,e})%x]
(1+(2-3)/4+[(a-({b+c}*5)/2)+e]
(a{b(c]}a)
I tried something like this, but I'm not exactly sure what I am doing wrong:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.Stack;
public class Driver {
[Code] .....
View Replies
View Related
Apr 26, 2015
I need a java program for getting name and address matching from oracle database. I need get all the customer name and address belonging to same person even if there is slight name and address changes are there.
James Smith
123 Broadway Av
Brownville, ME 04415
James S
123 Brodway Avenue
Brownville Junction, ME 04451
I am unable to get a best code for this and trying since long time.
View Replies
View Related
May 11, 2014
I am trying to write a program that checks for parentheses matching using stacks.This is my ArrayStack class.
public class ArrayStack{
private final int DEFAULT_SIZE=10;
public int tos;
Object[] array;
public ArrayStack(){
array=new Object[DEFAULT_SIZE];
[Code] ....
But the problem is when I compile matching I get an error as unreported exception EmptyStackException.must be caught or declared to be thrown. I think the problem is with exceptions which I don't have a good knowledge of.
View Replies
View Related
Apr 17, 2014
Here if we give input from a text file from a disk and (a[b+c{d}]-v) is true and{a-(b]} is false but i get some syntax errors ...
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Stack;
public class Syste {
private static String expr;
[code]....
View Replies
View Related