Automatically Proceed To Next Game After User Guessed Correct Number

Jun 17, 2014

I need the game to automatically proceed to the next game after the user has guessed the correct number. I don't know how to do this or what to add.

Here is my code:

import java.util.Random;
import java.util.Scanner;
public class HiLo
{
public static void main (String[] args)

[code]...

View Replies


ADVERTISEMENT

Hangman Type Game - How Many Times Each Guessed Letter Occurs Within The Word

Jul 31, 2014

The game runs fine, however I have to include how many times each letter that is guessed occurs within the word. For example, if the guess is e, the program should print out: The character e occurs in 3 positions. How would I go about doing this??

/*
* A program that plays simple word guessing game. In this game the user provides a list of words to the program.
* The program randomly selects one of the words to be guessed from this list.
* The player then guesses letters in an attempt to figure out what the hidden word might be.
* The number of guesses that the user takes are tracked and reported at the end of the game.
*/

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

[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

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

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

Translation Game - Translate A Word Proposed To And Check If Input Response Is Correct

Dec 19, 2013

The project is to develop the game Translate the Word .... It is asking user to translate a word proposed to and check if the input response is correct. At the end of the game score will be calculated and displayed.

Game Play :

1 - Ask the user to specify , through the console , its name and the number of words to offer . It is up to you to handle exceptions (eg number of words greater than the number you provided )
2 - Recover user response ( the word translated ) and check whether to continue . (eg you want to continue (y / n)) after each proposal.
3 - compare the response of the user with that which is preset for the word in question .
4 - Show the score at the end ( or at the breakpoint ) .
5 - Save the file in a user name , the score , the number of questions and the start date and end of the game played .

Some notes to consider :

1 - The language (eg, English - French , English - Arabic , etc. . ): It is up to you to specify the language adopted in the game and inform the user of your choice.
2 - The word bank to offer : It is up to you to develop the appropriate means to get the words to propose to the user. That said , the words and their translations can be retrieved :

a. a TXT file
b . an XML file . ( Tutorials DOM and SAX )
c . CSV file ( OpenCSV Tutorial )
d. a database ( Tutorial Access)
e . through APIs (eg Wordnet and google translate etc . ) .
f . a combination of the previous options a, bc , d and / or e . (eg words stored in a txt file and answers retrieved from the api google translate)
g . etc. .

Examples of files and databases are attached to the project statement . You will need to add one or more external libraries to your project. Click here for details on adding external libraries to Netbeans .

3 - A user will be associated with the question score if he can translate the word correctly. The score for each question can be calculated based on the number of words / questions to be proposed .

Development : In this project you will need at least a class called Question to encapsulate the word and its translations and provide all necessary methods to manipulate the object type Question.

An interface called IParser to make extensible project. Any class that implements IParser is a parser file (XML , TXT , CSV , etc.). / Database. In your project there will be a single class that implements IParser and will be used to retrieve words and their translations.

Add the ability to store the questions and answers of the user on the hard disk. Make the class Serializable Question

View Replies View Related

Forcing Correct User Input

Nov 23, 2014

I need to force the user to enter an integer between 1 an 11. The code below works great.... It will work fine if the user inputs any letter or character and reprompt for a number. However once a number is entered(a number out of range-or it would just accept the number) and then the user enters a letter or character that isnt an int the program crashes with a input mismatch exception. I see WHY it is doing this but I cant figure out how to put my while loops to fix this! Here is the code. Someone suggested to Catch the exceptions, then prompt for retry if I encounter one.. however I havn't used the try - catch for exception handling before. Here is my code.

public static int getDecadeSelection() {
int decadeChoice = 0;
System.out.println( "
Choose your decade: " );
System.out.println( " 1 - 1900-1909 " );
System.out.println( " 2 - 1910-1919" );
System.out.println( " 3 - 1920-1929" );
System.out.println( " 4 - 1930-1939" );
System.out.println( " 5 - 1940-1949" );

[Code] ....

It is because I am setting decadeChoice to console.nextInt, so once it passes that if the user inputs a letter it will crash, just not sure how to make it work.

View Replies View Related

Replace Correct Number Into Letter?

Mar 8, 2014

I'm trying to figure out the correct way to replace number into letter. In this case, I need two steps.

First, convert letter to number. Second, restore number to word.

Words list: a = 1, b = 2, f = 6 and k = 11.

I have word: "baafk"

So, for first step, it must be: "211611"

Number "211611" must be converted to "baafk".

But, I failed at second step.

Code I've tried:

public class str_number {
public static void main(String[] args){
String word = "baafk";
String number = word.replace("a", "1").replace("b","2").replace("f","6").replace("k","11");
System.out.println(word);

[Code] .....

Result for converting to number: baafk = 211611 But, result for converting above number to letter: 211611 = bkfk

What do I miss here?

How to distinguish if 11 is for "aa" and for "k"? D

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

Java - Replace Correct Number Into Letter

Mar 8, 2014

I'm trying to figure out the correct way to replace number into letter. In this case, I need two steps.

First, convert letter to number. Second, restore number to word.

Words list: a = 1, b = 2, f = 6 and k = 11.

I have word: "baafk"

So, for first step, it must be: "211611"

Number "211611" must be converted to "baafk".

But, I failed at second step.

Code I've tried:

public class str_number {
public static void main(String[] args){
String word = "baafk";
String number = word.replace("a", "1").replace("b","2").replace("f","6").replace("k","11");
System.out.println(word);

[Code] ...

Result for converting to number: baafk = 211611

But, result for converting above number to letter: 211611 = bkfk

How to distinguish if 11 is for "aa" and for "k"? Do you have any solutions or other ways for this case?

View Replies View Related

Program Keeps Prompting To Enter Correct Binary Number

Sep 10, 2014

I wrote a java program for my gui number converter app, the main purpose of this program is to make sure that user enters only a binary number for conversion from binary to other number formats. the problem is my program keeps prompting me to enter correct binary number, no matter if i enter correct binary number, it will still keep prompting me to enter correct number. Here is the code

import java.util.*;
public class test {
Scanner key = new Scanner(System.in);
String in;
int b;
public test()

[Code] .....

View Replies View Related

Web Services :: Telephone Book - Enter Phone Number / Correct Person With Name And Address Should Appear

Nov 30, 2014

Applications: Netbeans (8.0.1), Apache Tomcat

My Aim: Creation of a telephone book

How should it work:

I have a Database with Data of people (name, adress, phone number).

If a user enters a phone number (CLIENT) -> the correct person with the name and adress should appear.

I build up the infrastructure and now I'm at the point that I have to create a Webmethod for it. I just worked on projects like addition of two integers, hello "name", ... I think this example now is harder, BUT i can learn a lot!

View Replies View Related

Number Guessing Program - Computer Guesses A Number That User Is Thinking Of Within Certain Range

Mar 28, 2015

I have a beginning Java Program I have been working on that creates a number guessing program where the computer guesses a number that the user is thinking of within a certain range. I so far have the program below, but need getting rid of a few kinks/ adding features.

-First, I need to set it up so that the user will be prompted and give a range. It should run and produce something like this:

Welcome to this first-ever mind-guessing program!

Please pick a range (higher than 1 and no larger than 50): 32

You will choose a number between 1 and 32... and I will try to guess it.

With each of my guess, you will tell me whether I am too high (h or H), too low (l or L), match (m or M), or you want to quit (q or Q). My objective is to find the number using as few guesses as possible.

-Second, the game is supposed to give up and restart after failing the five, guesses, but for some reason, after it fails the fifth time, it prompts a fifth guess once again instead, then restarts after- I need to prevent this, so that it should look something like this:

My fourth guess is 17: h
My guess is too high?

My fifth guess is 16: h
*** I am unlucky this round. I give up.

Let's play!

My first guess is 10:
etc..

import java.util.*;
import java.lang.Math;
public class numguessprac1 {
// Declaring variables
public static String input;
public static int quit;
public static int guess;
public static int wins;

[Code] ....

View Replies View Related

User Enter 5 Digit Number And In Return List Each Number On Their Respective Lines

Sep 16, 2014

So I am currently writing my first assignment and have run into problems with my coding. The task was to have someone enter a 5 digit number and in return, I list each number on their respective lines. We also must create an error if a number other than 5 digits was entered. My problem is that when they enter a 1 or 2,3,4,6,7,8 digit number.. the error message occurs along with the rest of the messages (listing the numbers, etc). I want the program to end (or even re-ask to enter the numbers) if they incorrectly enter the data.

View Replies View Related

Program That Takes User Odd Number And Print Prime Numbers Lower Than User Input

Nov 4, 2014

I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.

public class PrimeNumber
{
Scanner scan = new Scanner(System.in);
int userNum;
String neg;

public void getUserNum()

[code]...

View Replies View Related

Program That Takes A User Inputted Number And Converts It To A Binary Number

May 5, 2014

trying to write a program that takes a user inputted number and converts it to a binary number.

Here's what I have:

package com.java2novice.algos;
import java.util.Scanner;
public class Converter {
static Scanner console = new Scanner(System.in);
public void printBinaryFormat(int number){
int binary = console.nextInt();

[Code]...

Bugs on:

Line 13
Line 17
Line 23

View Replies View Related

Java Lotto - Randomly Generate Five-digit Number And Prompts User To Enter Five-digit Number

Sep 25, 2014

1. 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.here is my code. I have tried replacing the && statements with || and it always returns either case 1 or case default.

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

View Replies View Related

Guessing Game Always Choose Same Number

Jan 4, 2015

I am using eclipse for this project. Every time I run this program the choose method will always choose 0. Ignore the Sleep.sleep() method, there is another class in the program that performs it.

import java.util.Scanner;
public class gamestart {
public static int num;
public static String name;
public static String diff;
public static String choice;

[Code] ....

View Replies View Related

How To Get User Response To Hit And Stick Game Play

Mar 14, 2015

I'm making a "very" basic blackjack game, and I'm stuck on how to get a user response to hit and stick game play.

import java.util.Random;
import java.util.Scanner;

class blackjack {
public static void main ( String[] args ) {
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
String money;
String name;

[Code]...

I know people will want me to tidy it up, or do it "their" way, but honestly I just need method of getting the user to press h or s and have the program continue under it's own steam.

View Replies View Related

Tracking Number Of Games Within Guessing Game

Aug 22, 2014

/*
/ GuessGame.java
*/

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

[code]....

tracking the number of games played, and also when running the code, I have to press "1" twice for it to actually load up the game again.

View Replies View Related

Broken Loop - Number Guessing Game

Jun 3, 2014

What's wrong with my code. It says 'you win' even when I guess an incorrect number. And then the 'win' message keeps repeating. I'm thinking I need a way to generate a new input? And then maybe take the 'win' message out of the loop, but that breaks it too.

View Replies View Related

Random Number Guessing Game With Three Tries (Loops)

Mar 8, 2014

I was told to write a program which generates a random number between 0 to 5 *including 5* and give the user 3 chances to guess this number:

-If the user enters a wrong number within 0 to 5, the user has lost one opportunity.
-If the user enters a number out of range, the program should prompt the user to enter a number within the range
-If the user has 3 unsuccessful attempts, the program will print the number.

I was also instructed to use :

Random randomNumber=new Random();
int i= randomNumber.nextInt(6)

I have attempted it and this is what i have so far.
 
import java.util.Random;
import java.util.Scanner;
public class Exercise1
{
public static void main(String[] args)
{
Random randomNumber=new Random();

[Code] .....

View Replies View Related

Lottery Game - Number Guessing Program

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

How To Prevent A User From Going Out Of Bounds In Simple Array Game

Apr 26, 2015

I am making a very simple 2D array game where the player is asked what size they would like the game board to be. After entering, it displays the board and the player 'P' starts at index [0][0]. After that, they are asked for an action, which can be "up", "down", "left", "right", or "exit". I will be including some extra later (like a treasure at the end, or random obstacles), but for now this is what the game consists of.

I was instructed to "do nothing" when/if the player attempts to go out of bounds. I am trying to simply print an error, such as "Out of bounds! Try again.", then prompt the player again for an action. I even tried to make a boolean method to catch it, but to no avail.

I don't want the exception to occur at all. I just simply want the error message to print to the player and ask for another action. I would prefer not to use try/catch, or try/catch/finally since I already tried that and it still gave the exception error.This program consists of two classes. I will show the class containing the main first, then the client-server type class second.

import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
World world = new World();
boolean keepPlaying;
keepPlaying = true;
boolean isOutOfBounds;
isOutOfBounds = false;
int height = 0;
int width = 0;
int x = 0;
int y = 0;

[code]....

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

Quiz Game Program - Random Number Generator

Nov 18, 2014

I've run into some problems with my Quiz-game program. What I basicly want it to do is generate a random number that is tied to the other windows I have for the program (I want a new random question to be generated once I have guessed on the first one). I've read about a few different ways to approach this but everything I get is a pure number generator.

I imported

import java.util.Random;

into my program but I don't know where to go from there.

View Replies View Related







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