A genious needed to figure out this code!!!!!

i have three points in the following code which i can't work it out
import java.awt.*;
import java.awt.event.*;
import java.applet.* ;
public class Hangman extends Applet implements ActionListener, ItemListener
/* problems
* 1) should replace all occurences of letter not just 1
* 2) no of guesses should not be allowed to be <0
* 3) win/lose message should be in color
// CONSTANTS
private static final int EASY = 0;
private static final int MEDIUM = 1;
private static final int HARD = 2;
private static final int BEGINER = 9;
private static final int INTERMEDIATE = 8;
private static final int ADVANCED = 7;
private static final int ANSWER = 26;
private static final int RESET = 27;
private static final int STRING_NOT_FOUND = -1;
private String[][] WorkingArray = new String[][]{
new String[]{"CAT","WREN","MOUSE","GERBIL"},
new String[]{"ROSE","GRASS","WILLOW","RAGWORT"},
new String[]{"SHIRT","JACKET","SANDALS","TROUSERS"}
private Button[] Keys = new Button[28];
private CheckboxGroup Diff = new CheckboxGroup();
private Checkbox[] Levels = new Checkbox[]{
new Checkbox("Beginner",true,Diff),
new Checkbox("Intermediate",false,Diff),
new Checkbox("Advanced",false,Diff)
private Panel Keypad = new Panel(new GridLayout(4,7));
private Panel P = new Panel(new FlowLayout());
private Label Title = new Label("Guess The Word");
private Label Prompt= new Label ("Guesses Remaining");
private TextField Word =new TextField(24);
private TextField Message = new TextField(24);
private TextField Guesses = new TextField(3);
private String LongWord = " ";// Long Word
private String ChaGuess = " ";// Guessed Charactor
private String s = " " ;
private int[] Level_Values = new int[]{9,8,7,} ;
private int Pos = 0 ;
private int LPos = 0 ;
private int NoOfGuesses = 9;
private int NoOfChars = 0 ;
private int WordLen = 0 ; // length of current word
private int ArrayIndex = 0;// Array, currently in use
private int ElementIndex = 0;// element, currently in use
public void init() { // build gui and register components for events
this.add(Title);
this.add(Word);
this.add(P);
this.add(Keypad);
this.add(Message);
// add radio buttons to gui and register for events
for (int x = 0 ; x < Levels.length ; x++){
Levels[x].addItemListener(this);
this.add(Levels[x]);
public void start (){
validate();
public void stop(){
invalidate();
public void destroy(){
public void actionPerformed( ActionEvent Click){
int LastPos = 0 ;
try { // handle button events
if (Click.getSource() == Keys[RESET]){
// Hide Messages and clear TextFields
Message.setVisible(false);
Word.setText("");
LongWord = " " ;
// Enable Letters
for (int x = 0 ; x < RESET ; x++){
Keys[x].setEnabled(true);
}// for
// Get Word to Display
ElementIndex = (int)(Math.random()*4); // random no between 0 - 3
WordLen = WorkingArray[ArrayIndex][ElementIndex].length();
NoOfChars = WordLen ;
for (int x = 0 ; x < WordLen; x++){
LongWord = LongWord +"-" ;
} // for
Word.setText(LongWord);
NoOfGuesses = Level_Values[ArrayIndex] ;
Guesses.setText(LongWord.valueOf(NoOfGuesses));
} // if
else if (Click.getSource() == Keys[ANSWER]){
Word.setText(WorkingArray[ArrayIndex][ElementIndex]);
Guesses.setText(" ");
// Disable Letters
for (int x = 0 ; x < RESET; x++){
Keys[x].setEnabled(false);
}// for
}// else if
else{
//event came from a letter
// get object from awt.event, cast to button to use label
ChaGuess=( ((Button)Click.getSource()).getLabel() );
LPos = WorkingArray[ArrayIndex][ElementIndex].indexOf(ChaGuess) ;
Pos = WorkingArray[ArrayIndex][ElementIndex].lastIndexOf(ChaGuess);
if (Pos == STRING_NOT_FOUND){
--NoOfGuesses ;
Guesses.setText(LongWord.valueOf(NoOfGuesses));
if (NoOfGuesses == 0 ) {
Message.setVisible(true);
Message.setText("You Lose");
} //if
else {
if (LPos == Pos){
LongWord = (LongWord.substring(0,Pos )
+ ChaGuess + LongWord.substring(Pos+1,WordLen));
--NoOfChars;
LastPos = Pos ;
else {
LongWord = (LongWord.substring(0,Pos )
+ ChaGuess + LongWord.substring(Pos+1,WordLen));
--NoOfChars;
Pos = WorkingArray[ArrayIndex][ElementIndex].indexOf(ChaGuess,LPos+1) ;
if ( Pos != STRING_NOT_FOUND) {
LongWord = (LongWord.substring(0,Pos )
+ ChaGuess + LongWord.substring(Pos+1,WordLen));
--NoOfChars;
Word.setText(LongWord);
if (NoOfChars == 0 ) {
Message.setVisible(true);
Message.setText("You Win");
}// end of try block
catch ( Exception E ){ // catches all exceptions
finally {
invalidate(); // mark window as needing to be redrawn
validate(); // redraw window
} // actionPerformed
public void itemStateChanged(ItemEvent Check){
// handle checkbox events
if (Diff.getSelectedCheckbox() == Levels[EASY]){
ArrayIndex = EASY ;
else if (Diff.getSelectedCheckbox() == Levels[MEDIUM]){
ArrayIndex = MEDIUM ;
else if (Diff.getSelectedCheckbox() == Levels[HARD]){
ArrayIndex = HARD ;
Guesses.setText(s.valueOf(Level_Values[ArrayIndex]));
invalidate();
validate();
public Hangman() {
char Tit = 'A';
String ButtonTitle = "A" ;
// construct keyboard and register for ActionEvents
for (int Cnt = 0;Cnt< Keys.length ; Tit++, Cnt++){
ButtonTitle = ButtonTitle.valueOf(Tit);
Keys[Cnt] = new Button(ButtonTitle);
Keys[Cnt].setEnabled(false);
Keys[Cnt].addActionListener(this);
Keypad.add(Keys[Cnt]);
Guesses.setText(ButtonTitle.valueOf(NoOfGuesses));
Guesses.setEditable(false); // make TextField ReadOnly
Word.setEditable(false); // make TextField ReadOnly
Message.setVisible(false);
P.add(Prompt);
P.add(Guesses);
Keys[ANSWER].setLabel("Answer");
Keys[RESET].setLabel("Reset");
Keys[RESET].setEnabled(true);
}// Hangman1
you help is appreciated

You do not need a genious man! You just need somebody who is willing to do your work :)

Similar Messages

  • Help, I just can't figure out this code or what to do to make it work

    ok, what i'm trying to do is the following: I created a class called Enrollement, in that class I put in an array of 30 objects to hold the places of 30 names that I used Scanner to bring in from a text file. Ok, that part of the code alone works fine. After that, I know want to write a function that will count the number of times each letter (a-z) appears in the first and last names in the class that are held in that array. I have been working on this for a while making changes doing a bunch of stuff but i keep getting errors with the second part that I honestly don't know how to fix or what i'm doing wrong. I am very new to Java. IF/when anyone responds, please dumb down your answers as much as possible so that I can understand what you are saying, I just have no idea what the errors mean or how to make this program work. my code is below:
    import java.util.Scanner;
       import java.io.File;
        class Enrollment{
           public static void main(String [] args)throws Exception{
             Person [] name = new Person [30];
             Scanner sc = new Scanner(new File("names.txt"));
             while (sc.hasNext()){
                String lastName = sc.next();
                String firstName = sc.next();
                sc.nextLine();
                System.out.println("Name: " + firstName + " " + lastName.substring(0,lastName.length()-1));
           public int chararcterCount(char c){
             int count = 0;
             for(int i = 0;i<30;i++){
                Person p = Person ;
    count = count + p.charCount(c);
    return count;
    public static void main(String [] args)throws Exception{
    Enrollment e = new Enrollment();
    e.print();
    System.out.println("Letter a appears " + e.characterCount('a') + times);
    keeps telling me that public static void main.... is already defined and i know that but once i delete that part from program i just keep getting more errors later and i just have no clue how to make this all work

    the program is supposed to count the number of times
    a certain letter appears in the first and last names
    of the class.I was asking about the particular code snippet you posted, not about the program.
    ....p.charCount is supposed to count the
    number of times that character appears, or at least
    that's what i want it to do, Does it do that? Did you test it? You should write a main method that just constructs a Person object and then call its charcount method for vairous characters--one that appears zero times, one time, and multiple times--and see if you get the right results.
    i'm not too sure of the
    rules aorund here and i don't know if this is taboo,
    but would it be possible tot talk to you in real time
    on AOL Instant Messenger or somethingNo, most people here (myself included) will not do that. It denies others the chance to learn from your problem, and prevents others who might help you from participating in the conversation.

  • Need help figuring out this nano...

    I got the new nano today because my old one went throught washing machine. So, I hook it up and many things pop up saying, "Cannot find file" "Cannot find disc" "Cannot find folder" and error code 1415, 1417, and (50)...but I read about them and it still wont work. Also, theres a thing, "Arcsoft Media Card Companion" that comes up asking me if I want to transfer files...crap, anybody have a clue whats wrong?

    Do you have the current version of iTunes installed. I understand it is necessary for the new versions of iPods/Nanos.
    Sharol

  • I am moving from Southern California to Maui, Hawaii and I need to figure out the best way to get my 24 inch iMac across the ocean. Does anyone know the best way to do this?

    I am moving from Southern California to Maui, Hawaii and I need to figure out the best way to get my 24 inch iMac across the ocean. Does anyone know the best way to do this? I have found GearGrip's LCD harness so that I can do carry-on onto the plane...  Or maybe use a Pelican Case to do it as a "checked bag"? Or any other suggestions??! Please help!
    Thanks so much!!

    I don't recommend you send the iMac in a checked bag. Might get damaged.
    Check the airlines website for carry on guidelines.
    Or, if you have the original box that the iMac came in, if you have someone who can pick up the iMac for you, send it ahead Fed Ex and insure the package.
    Just make sure the display is covered to protect it. A blanket perhaps.
    Aloha ...

  • TS3798 I get this error message"your operation could not be completed" I need help figuring out why I can not access the web page.

    I get this error message"your operation could not be completed" I need help figuring out why I can not access the web page.

    amarilysfl wrote:
    "Your disk could not be partitioned. An error occurred while partitioning the disk".
    https://www.apple.com/support/bootcamp/
    If you were using Apple's BootCamp and received this message, quit it and open Disk Uility in your Applicaitons/Utilities folder.
    Select the Macintosh HD partition on the left and select Erase and Erase Free Space > Zero option and let it complete (important) this will check the spare space for bad sectors that can cause issues formatting partitions.
    Once it's completed, try creating a partiton again in BootCamp.
    If that doesn't work, then hold command option r keys down while connected to a fast internet connection, Internet Recovery should load (spinning globe) and then in that Disk Utility, select your entire internal drive and click > First Aid > Repair Disk and Permissions.
    reboot and attempt Bootcamp again.
    If you still get a error, it might be that you have OS X data on the bottom area where BootCamp partition needs to go. This would occur if you had the drive or computer for a long time or wrote a large amount of files to the drive and nearly filling it up and then reduced some, but it left traces in the area BootCamp needs to go.
    To fix this
    BootCamp: "This disc can not be partitioned/impossible to move files."
    How to safely defrag a Mac's hard drive

  • HT4113 Can't figure out pass code and keeps disabling?  How do I reset this?

    Can't figure out pass code and keeps disabling?  How do I reset this?

    If you can't figure it out, you'll have to force recovery mode and restore the device.
    Follow the steps in this article:
    iOS: Device disabled after entering wrong passcode
    http://support.apple.com/kb/HT1212

  • I have an apple id but ı can not use it for sign in to itunes connect account while publishing my ibook document. Why ı can not login? What can ı do to figure out this problem?

    I have an apple id but ı can not use it for sign in to itunes connect account while publishing my ibook document. Why ı can not login? What can ı do to figure out this problem?

    As note already on the iBA forum [ AppleID for ibooks publishing ], you need two IDs. You can't use your developer ID.
    If you already signed up for books with that ID, you need to talk to Apple to straighten things out.

  • HT201365 Hello, someone stole my sons IPhone today in his gym class. I have the find my iphone app on my phone BUT he is not a listed device. I went into his itunes account and downloaded the app under his account. Now I just need to figure out how to use

    Hello, someone stole my sons IPhone today in his gym class. I have the "find my iphone app" on my phone BUT he is not a listed device. I went into his itunes account and downloaded the "find my iphone app" app under his account. When I try to log into "find my iphone" under his name on my device I get an error msg involving icloud......he is MUCH better at this stuff then I am BUT he is in school and now I  need to figure out how to use the "find my iphone app". PLEASE HELP

    It doesn't matter whick account you use to download the app.
    You have to sign into the app (or iCloud.com from a web browser on your computer) with his Apple ID & password.
    Find My iPhone will only work if it was enabled in the iCloud settings on the device and it was powered on with a connection to the internet

  • I have an IPad with a Restriction code that we cannot remember.  Is it possible to delete and restore the IPad without the code?  If not how do I figure out the code or how t? o remove it?

    I have an IPad with a Restriction code that we cannot remember.  Is it possible to delete and restore the IPad without the code.  If not how do I figure out the code or how to remove it?

    The only option is to wipe the device clean and restore it to factory settings.  Hope you have a backup.
    Follow the instructions in  iOS: How to back up your data and set up your device as a new device http://support.apple.com/kb/HT4137 to restore the device to factory settings.
    Once you have setup the device as a new one, you can then sync it back with your iTunes account and all your music, apps, contacts and any other content sync'ed with iTunes will be loaded on the device. Any content that is stored only on the device and not sync'ed with iTunes, like app logins or data, will be lost during this process. Be forewarned that this is a long process and can take a couple of hours or more to complete. This can be painful, but it is necessarily so to prevent users from working around the security settings. After the restore is complete, you can setup a new Restrictions passcode. Make a note of the passcode to avoid this situation in future.
     Cheers, Tom

  • I have a mac 10.5 and need help figuring out how to change my email settings so it does not automatically delete my inbox every 30 days.  How to I adjust the mail settings?

    I have a mac 10.5 and need help figuring out how to change my email settings so it does not automatically delete my inbox every 30 days.  How to I adjust the mail settings?

    I think it must be an IMAP account then, & in Mail>Preferences>Accounts>Advanced>Keep copies for Offline viewing:>Don't keep copies, then on the Server, or maybe it's just this one itself, but on the Server you have a setting to remove eMails after 30 days.
    If it's a POP account we'd have to investigate that... but you didn't say so I'm guessing here.

  • Need Help figuring out how to alphabetize itunes artist.

    I need help figuring out one more thing. I have my artist tab in my itunes library and I need to figure out how to get all the artists grouped together instead of being scattered all around.
    This is how it looks now:
    Justin Timberlake
    Linkin Park
    Linkin Park
    Linkin Park
    Justin Bieber
    Daughtry
    Linkin Park
    Linkin Park
    JoJo
    Linkin Park
    This is how I want it to look:
    Daughtry
    Justin Timberlake
    Justin Bieber
    JoJo
    Linkin Park
    Linkin Park
    Linkin Park
    Linkin Park
    Linkin Park
    Please help! Thanks!

    Enable the Sort Artist, Album Artist and Sort Album Artist columns so you can see what is going on. Album Artist normally takes precedence over Artist, with the Sort fields further controlling the order.
    See also Grouping tracks into albums.
    tt2

  • How do I get my previous contacts from mobileme now to the icloud? I need help figuring out how to make that transition?

    How do I get my previous contacts from mobileme now to the icloud? I need help figuring out how to make that transition?

    Try using the app My Contacts Backup, which will back up your contacts as an attachment to an email.  Send this email to yourself, open it on your Mac and double-click the attachment to import them to Address Book (or Contacts if you have Mountain Lion).

  • I need to figure out how to pay for another month of premiere... and it is very confusing... can someone help me?

    Need help figuring out how to pay for my renewal for Adobe Premiere. Anyone can tell me what to do?
    Thanks!

    Go to this webpage:
    Creative Cloud pricing and membership plans | Adobe Creative Cloud
    Click on the chat button (in the lower center of the page) or use the telephone number there.
    MtD

  • Need to figure out how to remove an unknown admin password on a mac.  used the install disc with not luck. tried some commands in single user mode, no luck.

    need to figure out how to remove an unknown admin password on a mac.
    used the install disc with not luck. tried some commands in single user mode, no luck.

    need to figure out how to remove an unknown admin password on a mac.
    used the install disc with not luck. tried some commands in single user mode, no luck.

  • I need to find a new email provider.  One that integrates well with my 'mail.'  I will also need to figure out how to notify everyone in my 'address book' of my change. I've been okay with earthlink but it's getting too expensive. Please advise.  Jack

    I need to find a new email provider.  One that integrates well with apple's 'mail.'  I will also need to figure out how to notify everyone in my 'address book' of my change. I've been okay with earthlink but it's getting too expensive. Can anyone help?  Jack

    I use a OLD G3 when I travel and mostly I am connecting over the satellites which is not really the best connection.
    I use GMX which is free and never have a problem getting my emails from anywhere even in the middle of the oceans.
    It does work using Apple mail and the adress book

Maybe you are looking for

  • Lack of week view in Calendar

    It appears to us that Apple has no sign to improve it although every user is unhappy with this shortcoming in the design of the Calendar. Any 3rd party software can fill this hole? What I am looking for is the week number can be shown in the icon lik

  • Query regarding SPML in OIM

    Hi All, I am working on SPML module of OIM. Really appreciate if someone could tell me the madness behind my curiosity  1.     Through SPML can we set/recover User's Challenge Question answer? I went through the search query response and couldn't ab

  • Error while check in rpd -MUD

    Hi experts, We are using obiee 10 G and have cluster environment and i configured our rpd for MUD. I am able to check out and make my changes but when trying to check in i get the error: This is in use by another user. No user is using it. Any sugges

  • Time-shifting on NHL Gamecenter--grayed out for hours?

    So I bought my ATV2 and Gamecenter subscription with the hope of time-shifting games. I'm in Alaska, so games start at 3 and 4 in the afternoon.  I prefer to watch around 9 pm, or 1 am Eastern time.  However, on most nights, as soon as the live feed

  • The Customer has requested complete delivery

    Hello all, I am unable to create a delivery, and I am getting the following message log  in the delivery creation Log. The Customer has requested complete delivery But my problem is, I dont know which item this is related to? How can i find out which