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


ADVERTISEMENT

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

Multi-word Hangman Game - Spaces Not Displayed When Program Run

Apr 9, 2015

I created a simple Hangman game. It functions correctly, the only issue is when the file contains a phrase (2 or more words), spaces are not displayed when the program is run. For example, if the phrase was Java Programming Forums.

It would appear as _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.

I want there to be spaces in between the words. How could I fix this? What would I need to add to my code?

import java.util.Scanner;
import java.io.*;
 public class hangman{
public static void main (String[] args) throws FileNotFoundException{
Scanner kb = new Scanner(System.in);
String guess;
String guesses = "";
int wrongGuess = 8;

[Code] ....

View Replies View Related

Create A Very Basic Hangman Type Of Game

Oct 12, 2014

You have to create a very basic hangman type of game. Open Notepad and create a list of at least ten words in a text file. Save the file as a .txt file and use it to read words for the game. In this game you do not have to show pictures but you do need to keep track of the amount of times that the user has guessed wrong. When the game starts, show the amount of characters in the word represented as dashes and ask the user to type in a letter. if the user guesses correctly show the word again with the correct letter filled in the correct positions(s) and if the user correctly guessed the word, show a message. If the user guesses wrong, keep track of the body parts that needs to be reduced with every wrong guess and inform the user as well, also show a message.

I'm struggling with reading the file, showing the amount of parts left and asking the user to play again. Here is the code:

package hangman;

/**
*
* @author
*/
import java.nio.*;
import java.io.*;
import java.util.*;
public class HangMan {

[code]...

View Replies View Related

Binary Tree - Storing Each Word As String And Int Frequency For Each Time Word Occurs

Apr 27, 2015

I have built a binary tree, from a file. In each node, I am storing each word as a string, and an int frequency for each time the word occurs. For the assignment, I need to find how many words occur only once in the file. I wrote the program, but for some reason I am getting a number different from what my professor is expecting.

As far as I know, this file has loaded into the tree correctly, because all of my other answers in the assignment are correct. What am I doing wrong?

public void findUnique() {
System.out.println("There are " + findUniqueWords(root, 0) + " unique words.");
}
private int findUniqueWords(Node subTree, int uniqueCount) {
// Base Case: At the end of the branch
if(subTree == null){
return uniqueCount;

[Code] ....

View Replies View Related

Keep Track Of Output - How Many Times Each Total Occurs

Jan 23, 2015

I am currently truing to make this class instantiate 100,000 dice rolls of 2 dice. And I also need to keep track of how many times each possible total occurs and I am having trouble outputting the result. Right now when I run my code it is just showing the results of each of the 100,000 roles.

public class ltefera_DiceRollTest {
public static void main(String[] args) {
ltefera_DiceRoll diceRoll = new ltefera_DiceRoll(10);
System.out.println("Total # of pips" + "
");
diceRoll.printArray();
System.out.println(diceRoll.countDice(2));
System.out.println(diceRoll.isArrayDataValid());
System.out.println(diceRoll.getTotal());
System.out.println(diceRoll.allDifferent());

[code]....

"how many time each possible total occurs"

View Replies View Related

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 View Related

Count And Return Number Of Times Integer Occurs In Array

Nov 16, 2014

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++) {

[Code]...

View Replies View Related

Java Hangman Program - Replace Correct Letter With The Blanks

Apr 28, 2014

How to replace correct letter with the blanks in the program. Last method in program used to print correct letters.

import java.util.*;
import java.io.*;
public class Hangman {
public static Scanner keyboard;
public static final int MAXSIZE = 15000;
public static final int NUM_GUESS = 8;
public static final int WORD_LENGTH = 20;

[Code] ....

View Replies View Related

How To Make Hangman Program Work For Phrases With More Than One Word

Apr 13, 2015

I created the following hangman program, but it only works for one word file inputs. How can I modify the program to make it work for files with a multiple word phrase?

/**This program is a basic Hangman game. It takes a word or phrase from a file, and then asks the user to guess the letters in it. The program ends when the user inputs 8 wrong guesses.
*/

import java.util.Scanner;
import java.io.*;
 public class hangman{
public static void main (String[] args) throws FileNotFoundException{
  Scanner kb = new Scanner(System.in);
  String guess;

[Code] ....

View Replies View Related

Program That Counts How Many Times A Letter Is Written

Sep 29, 2014

I can't get my code to print it like it's on the picture.

import javax.swing.JOptionPane;
import java.util.*;
public class BokstavTeller
{
public static void main( String[] args ) {
String input = JOptionPane.showInputDialog(

[Code] .....

View Replies View Related

Create Hangman Game With GUI?

Apr 18, 2015

I am trying to create a Hangman game with a gui. i already have buttons for the letters, each with its own action listener. I'm having difficulties creating the gallows and man.

I have a class called guiTest, which contains all of the letters. This is essentially what i have. Can I add the image to this class, or do I need to create a new class that extends JFrame?

Java Code: import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Container;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;

[code]....

View Replies View Related

Program A Hangman Game

Jan 18, 2014

i'm started to program a hangman game i Java not javascript i ecplice. the code so i can move forword just take the code and program it s it works.

import java.util.*;
public class GameLogic {
private boolean isStarted;
private int numberOfGuesses;
private int maxGuesses;
private List<String> guesses;
private String currentWord;

[code]....

View Replies View Related

String Of Words - Getting First Letter From Each Word?

Mar 26, 2014

If I have a string of words and want to get a letter from each word (let's say the first), how do I code for anything past two?

For example, if I have North Atlantic Treaty Organization and I want to convert it to NATO I would do something like:

charAt(0) for N
charAt(x + 1) for A

But what do I do for anything past the second string? If I do charAt(x ++ 1) I get an error.

View Replies View Related

Word Game (how To Check That Word Is In Dictionary)

Apr 21, 2014

import java.io.*;
import java.util.Random;
import java.util.Scanner; 
public class WordGame
{
public static void main(String[] args) throws IOException
{
final int RANDOM_LETTERS_COUNT = 10;
final int TRIALS = 10;
int score = 0;

[Code] ....

View Replies View Related

Convert The First Letter Of Every Word In A String To Uppercase?

Sep 20, 2014

I'm trying to convert the first letter of every word in a String to uppercase. I've managed to isolate the first letter of every word and then make it uppercase but I don't know how to replace it.

public static StringBuffer makeUpperCase(){
String str = String.valueOf(input2);
for(int i = 0; i < str.length(); i++){
if(str.charAt(i) == ' '){
char var = str.charAt(i + 1);
var = Character.toUpperCase(var);
System.out.println(var);
}
}

View Replies View Related

Replacing Underscores In Array Implementation Of Hangman Game

Jun 5, 2014

For an array implementation of a Hangman game I have created an array to hold the game board progress. It is initialized as "_ _ _ " where the underscores represent the number of letter in the word to be guessed. I have written the following method to replace underscores with a correct guess. It is functioning correctly in that it is replacing the underscore with a correct character guess, but it is only replacing the first time this letter appears in the word. I.e. for "greed" guessing "e" would only replace the first e: _ _ e _ _how I may be able to fix this issue.

// Updates gameboard from "_" to current guess if guess is correct
if (isCorrectGuess(move)==true){
if(inWinningState()==false){
guessProgress[charLocation] = guess;}
return true;}

View Replies View Related

Hangman Game Using Class - It Keeps On Bringing Up Exception Error

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

Improve Code To Output A Word With Most Frequent Letter?

Jan 31, 2015

The code is supposed to output a word from a sentence(from a sample file) with most frequently occurring letter in that word.

Example input: "Therefore, it is this word."

output: therefore

It currently uses 3 loops nested loops, is there a way to improve this?

public static String findWord(String file) throws IOException {
BufferedReader in = new BufferedReader(new FileReader(file));
String text, correctWord = null;
text = in.readLine();
StringTokenizer tokens = new StringTokenizer(text.toLowerCase(), " ,.?"); //split string into tokens of words only
int count = 0, numLetter = 0;

[code]....

View Replies View Related

Hangman Game - How To Scan The String For Input Supplied By User

Dec 9, 2014

My assignment is to create a hangman game. One of my first difficulties with it is how to scan the string for an input supplied by the user.

Here is my method:

//Guesses that character c is in the secret word.
//Updates all instance variables accordingly,
//and returns true if c is present in the secret word.
public boolean guessCharacter(char c){
}

View Replies View Related

Telephone Number - Write To A File Every Possible Seven-letter Word Combination

Nov 23, 2014

I am having some trouble with this program. The assignment is to write a program, given a seven-digit phone number, uses a PrintStream object to write to a file every possible seven-letter word combination that corresponds to that number. I have to avoid using 0 or 1. Here is my code.

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;
public class TelephoneGenerator
{
String phoneNumber;
char numberLetters[][] = {

[Code] ....

I am getting an error dealing with the main class.

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

Java Cannot Resolve Word Into Type?

Nov 3, 2014

I am creating a user friendly program that allows the user to adjust the dimensions of an oval (painted onto a window) via a 'slider' Everything is fine for the most part, except in the main code- when I tried coding for a window object for some reason java didn't recognize the type (that is, I used the keyword TheWindow and java didn't recognize it) the following is the full code set across 2 classes, but I think the problem is centered around the main class.

package javaIntermediate;
import java.awt.*;
import javax.swing.*;
//NOTE: this is 1 out of 3

[Code]......

View Replies View Related

Create Word Game Using Classes And Objects

Feb 14, 2015

For class, we need to create a word game using classes and objects.

The game is played in rounds. The player is presented with a word that is missing letters. The player has to fill in the missing spaces with their letter guesses. The words presented are chosen with a random number generator which has been provided for us. At the end of the game, the player is shown their score.

In steps, I have to:

-Welcome the player.
-Present the puzzle.
-Allow the player to fill in the blanks.
-Have the program check responses for correct/incorrect input.
-End the game if they have three misses, or continue if they complete the puzzle.

Now, to start, I have a class for the number generator, a class to store the array of 25 words, and a class for the game itself.

View Replies View Related

Word Puzzle Game - Add Extra No Occurrences

Oct 20, 2014

I have a simple Word Program here called PuzzleGame.java. It works perfectly but I wanted to add some bells and whistles to it. So I want to be able that if the user selects the same letter more than once a message comes up letting the user know that "That letter has already been selected, try another letter."

I am certain that if would go in the 'else' of the 'if( )' that I am providing.

import java.util.Scanner;
public class PuzzleGame {
public static void main(String[] args){
String secretPhrase = "BIG JAVA";
String guesses = " ";

[Code] .....

I am thinking maybe after the else in this if statement.

if(guesses.indexOf(secretLetter)== -1) {
System.out.print("-");
notDone = true;
} else {
//something here. I am not sure how to go about it.
System.out.print(secretLetter);
}

View Replies View Related

Design And Implement Word Guessing Game

Dec 29, 2013

I have a project about programing a game in java . In this project you are required to design and implement a word guessing game. In the game, user selects one of the available dictionaries (animals, plants, technical, names, etc. ), and the program randomly chooses one word from that dictionary and displays it by scrambling the letters. The user tries to guess the word while a guess counter starts to count down (lets assume it starts from 5).

While counter counts towards zero, the program chooses -randomly- two misplaced letters and puts them into correct positions to reveal the word more and give the user a hint. However, giving a new hint reduces the total value of the question. Lets say if the initial value of the question is 500 when all letters are scrambled, it reduces to 400 after 1st incorrect guess and hint, then after every incorrect guess it reduces more. You can determine the value of the question by the length of the word. The other details of the game is as follows:

1.You must design at least three classes (for example game, scrambledword, and dictionary).

2.Dictionaries are written in text files. If you design a class for dictionary, it must be constructed by a user chosen category ((animals, plants, technical, names, etc). In the constructor, the dictionary text file corresponding to this category must be opened and read; and words in that dictionary must be read into memory (e.g. String array). You must submit your dictionaries with your code. Do not share dictionaries between friends.

3.The game will record your total points and name in a text file where a hall of fame which has different users and their total points in 10 questions. You can design and implement a class for this.

4.Bonus+5%: Put user interface modules textboxes, buttons, etc Or

a.Use class hierarchy

b.Use of thread and timers and reducing the question value by timer instead of guesses.

View Replies View Related







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