Comparing Inputted Guess To Computer Random Sequence - Counter Not Working?

May 27, 2014

I have separated characters into an array that can be accessed from any method, however, when I try to compare the inputed guess to the computers random sequence, the counter always comes back as 0 (the comparison occurs in the checkColour method).

Java Code:

package mastermind;
import java.util.Scanner;
/**
* Program Description: play a game of mastermind versus the computer
*/
public class Mastermind {
private static int block1, block2, block3;
private static String blockColour1, blockColour2, blockColour3;

[Code] ....

The counter is called colourCorrect.. But I think the problem lies more in me converting the strings (input and computerGuess) into char arrays, as if I output the values at position in the array, I get numbers (but the numbers are not character values from the ascii table).

View Replies


ADVERTISEMENT

Counter Set Up For 20 People But Only Counts 19 If Error Inputted In GenreType

Oct 15, 2014

This is a piece of a program I am trying to write,my only problem is when an incorrect input is entered in "genreType" it still counts as a loop and therefore I do not end up with 20 results I am looking for..I have tried multiple different ways but nothing seems to work for me.

package assignment_1;
import javax.swing.*;
public class Assignment_1 { 
public static void main(String[] args) {
int rockCounter=0;
int popCounter= 0;
int danceCounter= 0

[Code] ....

View Replies View Related

Update Sequence Of Stars According To Actual English Word And Guess Character

Jan 12, 2014

Below is part Two the method I need creating:

This method updates the sequence of stars according to the actual English word and the guess character.

public static String updateSecretWord(String secretWord, String englishWord, String guessedChar)
{
}

Below is the example of how it should look like when I call it

updateSecretWord(“*****”, “Hello”, “h”) = h****
updateSecretWord(“h****”, “Hello”, “o”) = h***o
updateSecretWord(“he**o”, “Hello”, “e”) = he**o

View Replies View Related

Guessing Game GUI - Comparing Guess With Randomly Generated Number

Apr 13, 2014

package guess.the.numbers;
import java.awt.*;
import javax.swing.*;
import java.util.Random;
import java.awt.event.*;
ublic class GuessTheNumbers extends JFrame{
private JButton guessBtn;
private JButton restartBtn;

[Code] ....

I am getting a strange error and it almost seems like its not comparing it to the random generated number just the guess that i entered before. Here are my error messages.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at guess.the.numbers.GuessTheNumbers$ButtonHandler.actionPerformed(GuessTheNumbers.java:119)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)

[Code] .....

View Replies View Related

Counter To Count Random Occurrence

Jan 21, 2015

I have 2 classes a main one and another class. In the other class I have a method that has:

String gInfo(){
String[] Behavior = {"Sleeping", "Running home", "Studying", "playing pool", "walking to class"};
int rNum = (int) (Math.random() * Behavior.length);
return Behavior[rNum];
}

I call the gInfo() in the main class and run it through a loop 20 times. What I'm trying to do is get it to count the number of times that each behavior happens. and how to get it to work correctly.

View Replies View Related

Guess Picture Game - How To Sort Picture Random Every Time

May 3, 2014

I will write guess the picture game. I didn't find for example 4*4 picture how to sort picture random everytime ?

For example , when game start random various are 2734856127348561 two times same picture...

View Replies View Related

Comparing Array Or Int To 4 Digit Number From Random Generator?

Apr 4, 2015

How do I compare an array (or maybe int?) (example: 3572) to a 4digit number from random generator? how many of the four digit match the generated numbers.

View Replies View Related

Random Number Panel Not Working

Jun 3, 2014

I am trying to build a Jpanel that when you click the button it generates a random number between one and 100 and then display that number on the screen. It is supposed to start with a label that says Press the button to generate a random number between 1 and 100 and then when you press the button it changes the label to the random number generated. Everything has worked so far except the fact that it will not display the random number generated. It shows the button and the original string but it does't change it to the random number. Here is my code

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RandomNumberPanel extends JPanel {
private JButton RandomNumber;
private JLabel label;

[Code] ....

View Replies View Related

Get Computer CPU Usage?

Apr 7, 2014

I want to get current Computer CPU usage of my computer and display it in Console View of Eclipse? How can I achieve this?

My template code is:

Java Code: public class GetCPUUsage{
public static void main(String[] args){
System.out.println("CPU USAGE IS: ??????");
}
} mh_sh_highlight_all('java');

I added ??? as placeholder for CPU usage because I do not know how to retrieve RAM usage by Java.

View Replies View Related

ESP Game - Cycle Through Colors After Each Guess Entered

Dec 16, 2014

I'm writing an ESP game code for class. The problem is i cant get it to cycle through the colors after each guess is entered. It stays fixed on the original random number generated.

import java.util.Random;
import java.util.Scanner;
public class Final1 {
String colorInput, computerColor;
int computerNum, right, wrong;

[Code] ....

This repeats 10x but the color never changes from the initial random chosen.

View Replies View Related

Color Memory - How To Make Cursor Appear In Each Guess Box

Dec 7, 2014

This is my code. It is running great until I enter in the final color and hit enter. I get an Array Index out of bounds error, which I show at the bottom. I have fiddled with it, by moving the all answers correct into an if..else statement, hoping it would fix it. Needless to say, it didn't work.

Also, I am trying to figure out how to make the cursor appear in each guess box. It does in the first one, but after I hit enter, I have to click in the box each time to get one.

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class RobertMaloneChapter17 extends JFrame
{
//final variables to set the width and height of my frame

[Code] ....

My Errors:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 5
at RobertMaloneChapter17$Listener.actionPerformed(RobertMaloneChapter17.java:67)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:508)
at javax.swing.JTextField.postActionEvent(JTextField.java:721)

[Code] ....

View Replies View Related

How To Get The Actual Computer IP Address

Jan 31, 2014

I wrote a Chess game that uses socket to connect to another computer, and allow player vs player and player vs computer game sessions.

However, there is a problem which I noticed.

When you get the IP address of the computer in which the program is running, you are not getting the computer's actual IP, you are getting the Router's IP.

Is there a way to get around this.

So the problem is that when I go to another computer, located in a different house or lets say from my school, the program cannot connect back to my home IP, because it uses the router's ip, not the computer's ip I am running the server program.

Is there a way to get the Computer's IP, not the router's ip when summoning or invoking the get IP address method from the socket class?

When I say that the socket class is acquiring the router's ip, well that's done without my interfering...I don't know why it does that, it is somehow recognizing the router and not the computer.

The thing is that the server program is written that any client program is able to connect to the home server.

But when I run the program from a different location other than the current home, the sockets don't connect because it is somehow recognizing the router's ip not the computer's ip.

View Replies View Related

Java Random Road Cross - Generate Random Number Between One To Ten

Dec 8, 2014

The program I'm supposed to create generates a random number between one to ten. Then the program is to ask me if I wish to cross the road. If you choose to cross, the outcomes for 0-2 are "You crossed safely." For 3-5, 75% of the time it should say "RIP you got run over", and 35% of the time it should say "You crossed the street." For 6-8, 60% of the time it should say you made it.", and 40% of the time it should say "You died". For 9-10, it should say "RIP".

So far I have gotten the random number generation part working. I have up to here:

import java.util.Random;
public class test4 {
public static void main(String[] args) {
Random random = new Random();
for(int i =0; i < 1; i++){
int num = random.nextInt(10) + 1;
System.out.println("The number of cars on the street are: " + num + "Do you wish to cross the road?");
}
}
}

View Replies View Related

Hangman 2 Player Game - User Cannot Guess More Than 6 Times

May 27, 2014

I am creating a hangman code. So the game i am creating is 2 player, first player enters the word and second player guesses. i made the code but i don't know how to restrict the first player from adding random characters into the secret word because for my project the word can only contain letters. so i need making the code so the player 1 can only enter letters.

My code is below:

/**
* Auto Generated Java Class.
*/
import java.util.Scanner;
public class Hangman {
public static void main(String[] args) {
Scanner input= new Scanner(System.in);
String player1,player2;
int wrongguessamount = 0; //keeps the count of the amount of wrong guesses
int correctguessamount = 0; //keeps count of the amount of correct guesses
int maxincorrect=6;//makes sure the user cant guess more than 6 times

[Code] .....

View Replies View Related

Wheel Of Fortune - Guess Letters That Are Hidden In Characters

Jan 27, 2015

We have to make a wheel of fortune game. Once the above information has been taken, the game can commence. The board should look very similar to the example below if the above input was used. In order to get text to align correctly, use the System.out.format(…) method. It's 14 by 4, so would I use a 2D array? I think I can get the rest done by myself but it's the making of the board I'm having trouble with. Would I need to use a 2D array?

The board is supposed to look something like this to the viewer of the program, but they need to guess the letters that are hidden in the characters. :

* * * * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * * *

These are the hidden values the viewer cannot see and must guess. Therefore, each turn they will guess a letter and the letter will the revealed if the one they said happens to be in the phrase. They will have to get STAR WARS EPISODE IV"

* S T A R * * * W A R S * *
* * E P I S O D E * I V * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * * *

And the concealed letters; are Star Wars episode five a new hope. The # would mean where letters stand. So there first # would be S, the next would be T - and it would eventually spell out STAR WARS EPISODE IV.

So this is the board that's used to display the concealed letter, and there a list of the hidden letters below, like hangman.

import java.util.Scanner;
public class wheelof{
public static Scanner keyboard = new Scanner(System.in);
public static String puzzle1 = "";
public static String puzzle2 = "";
public static String puzzle3 = "";
public static String bonpuzzle = "";
public static String category1 = "";
public static String category2 = "";
 
[Code] ....

View Replies View Related

How Java Graphics Interact With The Computer

Mar 30, 2014

I know there are Java graphics classes, and how to use them to draw images in a window, but how do those classes interact with the screen to create the image? At the very base of it all, what is the code that is passing the computer the data to display on its screen? I'm asking because I've seen several ways to do Graphics/GUIS, a lot of them involve the Graphics class, but what is it inside all of that that that makes it work? Also, is everything else involving graphics (any other graphics libraries people write) pretty much "on top" of the Graphics class or is there something else within it more basic that is being used?

View Replies View Related

Display What The Computer Chose (GUI Boxes)

Nov 29, 2014

for my class we have to make a rock paper scissors game using GUI boxes. Everything is working fine I'm just having trouble displaying what the computer chose. In other words, after the user selects Rock, paper or scissors, the scoreboard just pops up displaying the score. Here's the last working program before I started tinkering with it.

// your code goes here
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;

[Code].....

View Replies View Related

Creates Array Of 3 Consecutive Ints (0 - 7) User Has To Guess What Those Numbers Are

Aug 16, 2014

I have the following program. In a nutshell, I creates an array of 3 consecutive ints and the user has to guess what those numbers are, knowing that they are between 0 and 7, this is from Head First Java. In the book, the code has a bug that is made on purpose and they challenge you to fix it. As you can see bellow, every time a user's guess matches a int in the array, the NumOfHits is increased by one. When the NumOfHits is 3 (the length of the array) the game finishes.

The bug is that if you guess 1 and 1 is in the array, if you type in 1, 3 times, I will increase the NumOfHits 3 times and end the game as if you had won. To solve the bug, you need to find a way to tell the program that if the user already guessed that number, it should no longer be taken into account and we shouldn't increase the NumOfHits if the same number is provided.

I "fixed" this by searching for the index of the number that matches an int of the array, and changing that index's value to 100, since the user knows that the numbers are between 0 and 7, they will not submit 100.

The result? If the user submits 2 and 2 is in the array, the value of its indexed is replaced by 100, so that if the user submits 2 again it doesn't count as a match.

Please see the comments in the code

import java.io.*;
import java.util.Arrays;

class DotCom{
int NumOfHits = 0;
int[] LocationCells;
public void setLocationCells(int[] locs){
LocationCells = locs;

[Code] .....

The code works, but for some reason, some times I get a ArrayIndexOutOfBoundsException run time error and it appears to be somehow random. This is what I saw on the command line earlier

C:Userspablo.alvarez>java launchDotCom

Enter a number: 3
missed
Enter a number: 4
hit
Enter a number: 5
hit
Enter a number: 7
missed
Enter a number: 5
missed
Enter a number: 4
missed
Enter a number: 3
missed
Enter a number: 4
missed
Enter a number: 5
missed
Enter a number: 6

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at DotCom.checkYourSelf(launchDotCom.java:16)
at DotComGame.startGame(launchDotCom.java:59)
at launchDotCom.main(launchDotCom.java:72)

As you can see here, 3 returned 'missed' but 4 and 5 returned hit. Since the numbers are in sequence and are only 3, it makes sense that the last number is 6 (4,5,6). You will then notice that when I submitted 3 and 4 again it returned 'missed' as expected, because the numbers were already matched earlier, but then when I submitted 6, it returned the error seen above.

Sometimes this doesn't happen at all, sometimes it happens at the 2nd guess or third, it appears to be somehow random. I'm familiar with the error message, but I don't see where I'm using an index that doesn't exist in the array. The only time I'm referencing an array index is on

LocationCells[index] = 100;

but the index variable will only hold a value if the int submitted by the user matches on of the values in one of the indexes, so how is it that I'm going over the number of available indexes?

View Replies View Related

Communication Between Two Separate Java Program In Same Computer

Sep 20, 2012

I have two separate java Program that run on the same
computer : Program -1 & Program-2 .

Explain Program-1 :

Name of Program -1 is “InputFrame” that is a simple frame that contain a JTextField and a Button and a JTextArea .

Explain Program 2 : Name of Program-2 is “OutputFrame” that is a simple frame that contain a simple JTextArea that this JTextArea is a Instance object from a class with name of “DisplayFrame” .

This instance object from class of “DisplayFrame” added to frame of “OutputFrame”.Now I want run both Program 1 & 2 simultaneously in the same computer and when I enter a text in JTextField in Program-1 and after click on the Button “OK” that Text Entered in this JTextField In addition to JTextArea in Program-1 display In JTextArea in Program-2 .

I do not want use a share file between two Program-1 and -2 Or DataBase .I want if Program-1 run but Program-2 is not running and i enter a text in JTextFeild in Program-1 , after running Program-2 that Entered Text Displaye in JTextArea in Frame of Program-2 .(Offline Message) .Both Source code of Program-1 and Program-2 is Attached .

View Replies View Related

Computer Wins Every Time At Connect 4 Game

May 9, 2015

I have to make my connect 4 game smarter with an algorithm that can beat the human every time. How to do it??

View Replies View Related

Pogo Games - Java Is Not Detected On Computer

Jun 6, 2013

I am unable to open Pogo Poker with out receiving an error message saying "Oops, Java is not detected on your computer" (or something similar). I have reinstalled it several times and get the same results.

View Replies View Related

Guess Number Game - Reveals Answer If User Input Is Wrong

Sep 1, 2014

The problem occurs after the user inputs the guess.... it either runs the for loop if guess = numtoguess and reveals the answer even if the user input is wrong.... or it always runs the first if statement in the while loop if guess!= to numtoguess... heres the code

public static void main(String[] args) {
String[] Answers = {"yes", "Yes", "No", "no"};
String Name = JOptionPane.showInputDialog(null, "Hello, What is your name?","Random Game", JOptionPane.QUESTION_MESSAGE);
String UI = JOptionPane.showInputDialog(null, Name + " do you want to play a game", "Random Game", JOptionPane.QUESTION_MESSAGE);

[Code] ....

View Replies View Related

How To Write A Computer Based Testing Program Using Files

Jan 8, 2015

I'm supposed to write a computer based testing program using files. I have started writing however, I am stuck. I am to prompt the user to enter the file name 'test.dat" and if something different is entered then a error message should be displayed. Also the file will create an input stream for the data using the file. I am to have the user enter other information about an employee and then write the record to the file.

The program should be created so when the user enters "quit" the loop is terminated and the file is closed. I'm not asking for code. I was just giving a brief synopsis of the project. Where I am stuck is I wrote the first part of the program that creates the file; however when I enter a wrong file name the exception error message does not display. The code is below:

import java.io.*;
import java.lang.*;
import java.util.*;
public class Project5Write
{
private Formatter x;
public void openFile(){

[Code]...

View Replies View Related

JRE :: Keep Temporary Files On My Computer Via Command Line On Windows

May 18, 2015

I need to activate the setting 'Keep temporary files on my computer' (Java control panel/general/settings) on about 150 Windows 7 PCs in a Samba3-Environment (which does not have GPOs). We are running Java Version 8 Update 45 (build 1.8.0_45-b14) on all of the PCs. Is there a way to change this setting with the command line, a registry entry or somehow else?

View Replies View Related

Swing/AWT/SWT :: Hangman Game - No Graphics Show Up On Eighth Guess (Blank Frame)

Feb 5, 2015

I'm having some problems with the graphics of my hangman game. The graphic that's supposed to show up on the first guess (the hangman pole) doesn't show up until guess number 2. And on the eighth guess, no graphics show up (I just get a blank frame).

import java.awt.*;
import javax.swing.*;
public class HangmanFigure extends JPanel {
private int guesses;
private Image background;
public HangmanFigure() {
super();

[Code] .....

View Replies View Related

Get Current RAM Usage Of Computer And Display It In Console View Of Eclipse?

Apr 7, 2014

I want to get current RAM usage of my computer and display it in Console View of Eclipse? How can I achieve this?

View Replies View Related







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