Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6008551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:50:26+00:00 2026-05-23T01:50:26+00:00

/* * * Hangman.java * The program asks the user to choose a file

  • 0
/*
 * 
 * Hangman.java 
 * The program asks the user to choose a file that is provided. 
 * The program will read one line from the file and the player will guess the word.
 * and then outputs the line, the word will appear using "_".
 * The player will guess letters within the word or guess entire word,
 * if the player guesses correctly the "_" will replaced with the letter guessed. 
 * But, if the player guesses incorrectly the a part of the stickman's body will be added,
 * then the user will be asked to guess again. The user can also enter "!" to guess the entire word,
 * if  the guess correctly they win, but if they guess incorrectly they will be asked to guess again.
 * Once it has finished reading the file, the program outputs the number of guesses.
 */
import java.awt.*;
import hsa.Console;
//class name
public class Hangman
{
    static Console c;
  public static void main (String [] args)
  {
    c = new Console ();  
c.println("Hello, and welcome to Hangman!");
    PrintWriter output;
    String fileName;
//ask user to choose file; file contains words for user to guess
    c.println ("The categories are: cartoons.txt, animals.txt, and food.txt. Which category would you like to choose?");
    fileName = c.readLine ();    
    // R:\\HNMRY\\ICS3U10\\Assignments\\Sumbit your work for marks here\\Frank, Tracy\\+fileName
try {

            /*  Sets up a file reader to read the file passed on the command
               line one character at a time */
            FileReader input = new FileReader(args[0]);

            /* Filter FileReader through a Buffered read to read a line at a
               time */
            BufferedReader bufRead = new BufferedReader(input);

            String line;    // String that holds current file line
            int count = 0;  // Line number of count 

            // Read first line
           line = bufRead.readLine();
            count++;

{
  lineCount++;
  output.println (lineCount + "   " + line);
  line = input.readLine ();
}
            // Read through file one line at time. Print line # and line
           while (line != null){
               c.println(count+": "+line);
                line = bufRead.readLine ();
                count++;
           }

            bufRead.close();

        }
    catch (FileNotFoundException e)
    {
      c.println("File does not exist or could not be found.");
      c.println("FileNotFoundException: " + e.getMessage());
    } 
    catch (IOException e) 
    {
      c.println("Problem reading file.");
      c.println("IOException: " + e.getMessage());
    }
final String GUESS_FULL_WORD = "!";

// set integer value for number of letters for the length of the secret word
// set integer value for the number of guesses the user have made. starting at zero.
    int numberofletters, numberofguesses;
    numberofguesses = 0;
// guessletter indicates the letter that the user is guessing
// guessword indicates the word that the user is guessing after typing "!"
// new screen indicates the change made to the screen
// screen is the game screen that contains all the "_"'s
    String guessletter, guessword, newscreen;
    String screen = "";
    numberofletters = SECRET_WORD.length ();

// for every letter there is in the secretword, add a "_" to screen.
    for (int numdashes = 1; numdashes <= numberofletters; numdashes ++)
    {
      screen += "_";
    }

//Array to check letters entered by user 
final int LOW = 'A';  //smallest possible value
final int HIGH = 'Z';  //highest possible value

int[] letterCounts = new int[HIGH - LOW + 1];  
String SECRET_WORD;
char[] guessletter;
int offset;  //array index
// set constants for the secret word and also "!" to guess the full word
final String GUESS_FULL_WORD = "!";

// set integer value for number of letters for the length of the secret word
// set integer value for the number of guesses the user have made. starting at zero.
int numberofletters, numberofguesses;
numberofguesses = 0;

// guessletter indicates the letter that the user is guessing
// guessword indicates the word that the user is guessing after typing “!”
// new screen indicates the change made to the screen
// screen is the game screen that contains all the “_”‘s
String guessletter, guessword, newscreen;
String screen = “”;
numberofletters = SECRET_WORD.length ();

  /* prompt user for a word */
c.print("Enter a letter: ");
guessletter = c.readLine();
// start guessing!
// keep the user guessing (do while loop) until user types in "!" or the game screen is all filled with letters
// add one to numberofguesses to as a counter for the guesses the user makes
// A string lu(Letters Used) is created to hol the letters the user has already guessed.
String lu;
Boolean canPlay = true; 
    do
    {
    c.println ("(TYPE (!) TO GUESS THE WHOLE MYSTERY WORD!)");
    c.println (screen);
    c.println ("Please guess a letter:  ");
    guessletter = c.readLine ();
    numberofguesses = numberofguesses + 1;
// change user's guessed letter to upper case.
    guessletter = guessletter.toUpperCase ();
// make an index for which space the guessed letter is in the secret word.
    int indexof = SECRET_WORD.indexOf (guessletter);
// if the guessed letter DOES appear in the secret word
// then replace the guessed letter on the corresponding dash on the newscreen
// the dashes that is in front of the corresponding dash and behind it is not changed to the current newscreen.
// the replace the information of the old screen with the new screen.
    if (indexof > -1)
    {
      newscreen = (screen.substring (0,indexof) + guessletter + screen.substring (indexof+1));
      screen = newscreen; 
    }
    }while (GUESS_FULL_WORD.compareTo (guessletter)!= 0 && SECRET_WORD.compareTo (screen) !=0);

// if the screen equals the secret word (the dashes are all replaced with letters)
// then indicate that the user have won.
// also include the secret word and the number of guesses the used have made.
    if (screen.equals (SECRET_WORD))
    {
      c.println ("WOW!! YOU WON!! (:");
      c.println ("The scecret word was..." +SECRET_WORD);
      c.println ("You've guessed the total of " +numberofguesses+ " times");
    }
// if the user enters "!" then
    if (guessletter.equals (GUESS_FULL_WORD))
    {
    c.println (screen);
// allow the user to guess the whole word.
    c.println ("What is the secret word?  ");
    guessword = c.readLine ();
// change the user's guess into upper case
    guessword = guessword.toUpperCase ();

   if (numberofguesses==6)
{
canPlay = false;
Lose();
}
else
/*
* Put man here
          --
          o |
         /|\|
         / \|
         _____
*/
        String man[] = new String[7]
        man[0] = " --\n   |\n   |\n   |\n_____\n";
        man[1] = " --\n o |\n   |\n   |\n_____\n";
        man[2] = " --\n o |\n/  |\n   |\n_____\n";
        man[3] = " --\n o |\n/| |\n   |\n_____\n";
        man[4] = " --\n o |\n/|\\|\n   |\n_____\n";
        man[5] = " --\n o |\n/|\\|\n/  |\n_____\n";
        man[6] = " --\n o |\n/|\\|\n/ \\|\n_____\n";
char g1[] = guess.toCharArray();
        char w2[] = word.toCharArray();
        c.println(man[0]);
        for(int x=0;x<g1.length;x++)
        {
          c.print(g1[x]);
        }
        c.println();

// inside the if-statement...
// if the user's guess (full word) match with the secret word then
// indicate that the user have won.
// also include the secret word and also the number of guesses the user have made.
    if (guessword.compareTo (SECRET_WORD) ==0)
    {
      c.println ("WOW!! YOU'VE GUESSED IT!! (:");
      c.println ("The scecret word was..." +SECRET_WORD);
      c.println ("You've guessed the total of " +numberofguesses+ " times");
    }
// if the user's guess (full word) does not match with the secret word then
// indicate that the user have lost.
// also include the secret word and also the number of guesses the user have made
    else
    {
      c.println ("OOPS...! YOU LOSE!! ):");
      c.println ("The scecret word was..." +SECRET_WORD);
      c.println ("You've guessed the total of " +numberofguesses+ " times");
    }
    }
**7 errors found:**
File: H:\My Documents\Dr. Java\Hangman.java  [line: 166]
Error: H:\My Documents\Dr. Java\Hangman.java:166: not a statement
File: H:\My Documents\Dr. Java\Hangman.java  [line: 166]
Error: H:\My Documents\Dr. Java\Hangman.java:166: ';' expected
File: H:\My Documents\Dr. Java\Hangman.java  [line: 166]
Error: H:\My Documents\Dr. Java\Hangman.java:166: not a statement
File: H:\My Documents\Dr. Java\Hangman.java  [line: 166]
Error: H:\My Documents\Dr. Java\Hangman.java:166: ';' expected
File: H:\My Documents\Dr. Java\Hangman.java  [line: 166]
Error: H:\My Documents\Dr. Java\Hangman.java:166: not a statement
File: H:\My Documents\Dr. Java\Hangman.java  [line: 166]
Error: H:\My Documents\Dr. Java\Hangman.java:166: ';' expected
File: H:\My Documents\Dr. Java\Hangman.java  [line: 203]
Error: H:\My Documents\Dr. Java\Hangman.java:203: reached end of file while parsing
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:50:27+00:00Added an answer on May 23, 2026 at 1:50 am

    At a bare minimum, you need a semicolon here:

    String man[] = new String[7]
    

    Change this to:

    String man[] = new String[7];
    

    That’s the problem on line 166. The problem on line 203 may be fixed by that or it may be indicative of the absence of a closing brace } (or simply mismatched braces) somewhere in your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from Tkinter import * import Tkinter as tk import tkMessageBox import time import re
I'm trying to let the user chose the length of the word they want,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.