Java help needed
Create a web application that will allow a user to play the popular Hangman computer game using Java application program.
How to play Hangman:
The computer will randomly choose a word from an array. This array must have a minimum of 10 words and must be loaded from a text file of words. A sample text file named Words.txt is created. The same number of labels, as there is letters in the chosen word must be displayed on the game frame screen so that the user knows how many letters are in the word.
The user will try to guess the word by clicking a letter from a display of all letters of the alphabet (or by typing in the letters in the labels). Each letter is a separate button that can be clicked.
Each time the user chooses a letter, the computer checks to see if that letter is in the chosen word in the right position. If the letter is in the word, it will be displayed in the correct position and a message of correct will be displayed. If it is not in the word, a part of the man will be drawn on the game screen. The object of the game is to try and guess the word before the man is hanged. If the man is hanged, i.e. after 6 loses, the user loses and the correct word is displayed.
The program must also ask the user whether they wish to play again and keep scores for the user for a playing session. The following statics must be displayed per playing session on the web form: number of games played, number correct and number lost. Also have an option to allow the user to add new words to the file.
Instructions:
1. Display however many labels as needed by the number of characters of the chosen word.
2. Add 4 buttons or menu options: One for accessing help using the program, one for adding new words, one for clearing the screen/ restart/ Start a new game and one for exiting the program.
3. In the correct event handler, write program code to check if the entered letter is the correct letter.
4. If the letter is incorrect display or draw one part of the man(One of the body part images)
5. If 6 parts of the man�s body is displayed, the user loses. Report that the game is over.
6. If the clear game/restart/new game button is pressed reset all labels to empty and choose another word.
7. If the help button is pressed, show a help screen that gives instructions on how to use the game.
View Answers
August 23, 2012 at 11:37 AM
Here is a simple program of Hangman game.
import java.util.*;
public class Hangman{
public static void main( String[] args){
Scanner scan = new Scanner( System.in);
int totalMistake = 0;
boolean b = false;
System.out.println("Welcome to Hangman Game:)!!" );
SecretWord word = new SecretWord();
Input input = new Input();
while(totalMistake < 4 && !word.isSolved()){
System.out.println(word);
char c = input.getNewLetter();
if (!word.update(c))
totalMistake = totalMistake + 1 ;
}
if (word.isSolved())
System.out.println("Great, you done it.");
else
System.out.println("Sorry, too many errors.");
}
}
class SecretWord{
String visible, secret;
public SecretWord(){
String [] wordList = { "Giraffe", "Camel", "Lion", "Bear","Zebra","Monkey","Leopard","Rhinoceros","Elephant","Dear" };
int rand;
rand = (int) (Math.random()*4);
secret = wordList[rand];
int wordLength = secret.length();
visible = "";
for( int i = 0; i < secret.length(); i++){
char c = secret.charAt(i);
if( c == ' ' )
visible += c;
else
visible += '_';
}
}
public String toString(){
return visible;
}
public boolean update(char c){
char[] secretArray = new char[secret.length()];
char[] visibleArray = new char[secret.length()];
String s = "";
boolean contains = false ;
for(int i = 0; i < secret.length(); i++){
secretArray[i] = secret.charAt(i);
visibleArray[i] = visible.charAt(i);
}
for(int k = 0; k < secret.length();k++){
if(secretArray[k] == c){
visibleArray[k] = c;
contains = true;
}
}
for(int m=0; m < secret.length(); m++ )
{
s = s + visibleArray[m];
}
visible = s;
return contains;
}
public boolean isSolved()
{
return secret.equalsIgnoreCase(visible);
}
}
class Input
{
ArrayList<String> keyList ;
boolean chosen;
public Input()
{
keyList = new ArrayList<String>();
}
public void keyChosen( String key )
{
keyList.add( key );
}
public boolean hasBeenChosen( String key)
{
chosen = keyList.contains( key );
return chosen;
}
public char getNewLetter()
{
Scanner scan=new Scanner( System.in);
char a;
boolean chosen;
String aTmp;
do
{
System.out.println("Enter a Letter");
a = scan.next().charAt( 0);
aTmp = "" + a;
chosen = hasBeenChosen( aTmp);
if(!chosen)
keyChosen( aTmp);
else
{
System.out.println("You've already used that one. Please enter a new Letter");
}
}
while(chosen);
return a;
}
}
August 29, 2012 at 9:34 PM
Can you please show me how to do the following using Jframe form?
Related Tutorials/Questions & Answers:
Java help neededJava help needed Create a web application that will allow a user to play the popular Hangman computer game using
Java application program.
How... as
needed by the number of characters of the chosen word.
2. Add 4 buttons or menu
help needed for a program - Java Beginnershelp needed for a program i am having trouble understanding on what to code, so can some 1
help me out here. thanks in advance. Part I Write, compile and execute a
Java program that displays the following prompts
Advertisements
help needed - Java Interview Questionshelp needed What are the new features added in jdk 1.5? Hi friend,
The following were the new features added in
java 1.5....
* Autoboxing/unboxing
-------------------------
This link will
help you
urgent help needed in JDBC AND JAVA GUI - JDBCurgent
help needed in JDBC AND
JAVA GUI my application allows... want any one to
help me convert from scanner to
java GUI for this code...();
}
}
// thanks for any
help rendered
Hi Friend,
Try the following code
help Needed with requirementshelp Needed with requirements Following are my requirements :
* Maintain a student database
*Based on a student's test results ,reports should... develop it in
Java and it has to be a web app
Help needed in JSPHelp needed in JSP Hi .. I want to Update the multiple values of database using checkboxes and want to set the session for selected checkboxes..? please answer if any one knows as soon as possible
Code Help NeededCode
Help Needed I am trying to
help a buddy of mine with this program and I can't seem to figure it out. I am still working on it but any
help...[test]); line. Again thank you for any
help.
import java.util.*;
import
look up values help neededlook up values
help needed Hi,
I have a table that returns rows with a total weight (say 212.5 for example).
I have another look up table that has... of 2.55 as 212.5kgs is between 195.5 and 220.5
can anyone
help how I can do
Help needed for Form Validation please help!Help needed for Form Validation please
help! I have created a page which has login as well as Signup fields. I validated the login part by using jsp...;%@ page language="
java" session="true" %>
<%
//Getting the text
PHP help needed - Development processPHP
help needed This is my code that I am using for search engine, can any body answer how to cheange the code if I want limited and per page result display???
code
Career Search result
Yami says
<?php
servlet redirect problem help neededservlet redirect problem
help needed package p;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import
servlet redirect problem help neededservlet redirect problem
help needed package p;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import
Help needed for J2me and PHP - Development processHelp needed for J2me and PHP Hello Sir
I am a degree student. I have a small CRM application using J2me and PHP. I want to do cryptography using... but could not get result. I will appreciate your
help.
Regards
Needed java codeNeeded java code 1.Java code for the time used to display your name, one character at a time, for 200,000 times .
2.Java code for the time used to display your name, one character at a time in reverse order, for 200,000 times
urjent code needed - Java Interview Questionsurjent code needed Coding:
- We have Document domain/entity object with properties of Long id, String fileName, String filePath, int docId.
Please write a
java code that will:
1. Implements hashCode() and equals
java help! java help! I need
help starting off a program I am trying to write for class. The class should contain a private instance variable to represent temperature in Degrees Celsius and it should have the following methods
Help With Java...Help With
Java... Write a
java program that can take a positive integer greater than 2 as input and write out the number of times one must repeatedly divide this number by 2 before getting a value less than 2
help in javahelp in java
Rational Numbers
Rational numbers are numbers that can be represented as a fraction p /
q where p is an integer number and
q is a positive integer (
q != 0). Design and implement a
Java class
RationalNumber
help in javahelp in java Write an application that prompt the user to enter a number to use as an array size, and
then attempt to declare an array using the entered size.
Java generates a NegativeArraySizeException if wou attempt to create
java help?java help? Write a program, where you first ask values to an array with 6 integer values and then count the sum and average of the values in methods (send in the array & return the counted value to the main program). Print
java help java help Write a
Java program that does the following:
1.Creates a grading program based on the Baker College grading standard. You will need to look up the current grade standard. You may use only the letter grades without
help for javahelp for java 1.convert the following Pseudo code to
java if/else structure
if student?s grade is greater than or equal to 90 Print ?A?
else
if student?s grade is greater than or equal to 80
Print ?B?
else
help in javahelp in java 3.Flights
Design and implement a class called Flight that represents an airline flight. It should contain instance data that represents the airline name, flight number, and the flight's origin and destination cities
help in javahelp in java Write a program that will evaluate simple expressions such as 17 + 3 and 3.14159 * 4.7. The expressions are to be typed in by the user. The input always consist of a number, followed by an operator, followed
help in javahelp in java Design and implement a class called Sphere that contains instance data that represents the sphere's diameter. Define the Sphere constructor to accept and initialize the diameter, and include getter and setter
help in javahelp in java The factorial of a nonnegative integer n is written n! (pronounced ââ?¬Å? n factorialââ?¬Â?)
and is defined as follows:
n!=n . (n-1) . (n-2) . .... . 1 (for values of n greater than or equal to 1) and
n!=1 (for n
help in javahelp in java Gross And Dozens
Design and implement a class called GrossAndDozens to convert a given number of eggs into the number of gross, the number of dozens, and to the number of left over eggs. If you have N eggs, then you
help in javahelp in java Shopping cart
Create 3 shopping carts from a Cart class. Each class should have four items in it, a title, a price for the 4 items and the number of each. Your shopping cart should use private variables, so use
help in javahelp in java
Team Roster
Create a program called TeamRoster that uses a class called Roster. Roster should contain a team name and the names of all...
or
help me on this pleas..
7. Gross And Dozens
Design and implement a class
help in javahelp in java Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have a number
help in javahelp in java Temperature
Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have
help in javahelp in java Create 3 shopping carts from a Cart class. Each class should have four items in it, a title, a price for the 4 items and the number of each. Your shopping cart should use private variables, so use getter and setter
help in javahelp in java Create a class named Order that performs order processing of a single item. The class has five
instance variables (fields) : customer name, customer number, quantity ordered, unit price, and
total price. Define
help in javahelp in java Define a class named Money whose objects represent amounts of U.S. money. The class will
have two instance variables of type int for the dollars and cents in the amount of money.
Include a constructor with two
java helpjava help How to Open CSV Files in a Microsoft Excel Application Using
Java Code with example pgm
java helpjava help 1) build class(es) for the dresses, choose (dress ID, color, price, designer)( link lists)
2) construct the driver class by establishing two separate objects for each sister
3) let them both to enter the dresses
java helpjava help Rational numbers are numbers that can be represented as a fraction p /
q where p is an integer number and
q is a positive integer (
q != 0). Design and implement a
Java class
RationalNumber for representing such numbers
Java helpJava help Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a Floating-point number for the temperature and a character for the scale: either 'C' for Celsius or 'F
Java HelpJava Help Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a Floating-point number for the temperature and a character for the scale: either 'C' for Celsius or 'F
java helpjava help Design and implement a class called DateWriter that has three instance variables:
a string for month, an integer for day, and an integer for year. The class should has
a constructor to accept and initialize the values
HELP Java as a starter!HELP Java as a starter! I feel like my mind is going to blow! I... programming with
Java and I cant find a guide that?s neat. In till someone told me to read (Thinking in
java) I was about to buy it in till I saw the pages 1600! pages
Intro Java help with DoubleIntro
Java help with Double I have to evaluate a math expression using double in
Java. I can input the code fine for the expression, but I don't know how to view the answer that it gives me.
help Java help - Java BeginnersJava help I didnot get the code ,therefore I am posting my question again..
Thanks in advance ...:)
Programming Assignment:
A) Consider....
· Find the additional ADTs
needed to solve this problem.
· Rewrite