Last Update: Nov. 24, 2025

CT PS7: Control Structure, Arrays, Chars

This assignment is designed to use arrays and chars as data types. It is also designed to continue to improve your skills in writing Java programs using various control constructs.

Due: 11:55 PM, Sunday, November 30, 2025

Part 0: Program Analysis (Offline Learning)

Watch this video on how to analyze program with assertions. (pptx, pdf)

Part 1: Problem Specification

For this assignment, your mission is to write a program that plays the game of Hangman which works like this: the computer first selects a secret word at random from a list built into the program. The program then displays a row of dashes---one for each letter in the secret word---and asks the user to guess a letter. If the player guesses a letter that is in the word, the word is redisplayed with all the instances of that letter shown in the correct positions, along with any letters correctly guessed on previous turns. If the letter does not appear in the word, the player is charged with an incorrect guess. The player keeps guessing letters until either (1) all the letters in the word have been correctly guessed or (2) the player has made eight incorrect guesses. Here is a sample run that illustrates the play of the game:


Sample Run:

    Welcome to Hangman!
The word now looks like this: -----
You have 8 guesses left.
Your guess: A There are no A's in the word. The word now looks like this: ----- You have 7 guesses left. Your guess: E There are no E's in the word. The word now looks like this: ----- You have 6 guesses left. Your guess: I There are no I's in the word. The word now looks like this: ----- You have 5 guesses left. Your guess: O There are no O's in the word. The word now looks like this: ----- You have 4 guesses left. Your guess: U That guess is correct. The word now looks like this: -U--- You have 4 guesses left. Your guess: S There are no S's in the word. The word now looks like this: -U--- You have 3 guesses left. Your guess: T There are no T's in the word. The word now looks like this: -U--- You have 2 guesses left. Your guess: R There are no R's in the word. The word now looks like this: -U--- You only have one guess left. Your guess: N There are no N's in the word. You're completely hung. The word was: FUZZY You lose. Play another round of Hangman (y/n)? y
    Welcome to Hangman!
The word now looks like this: --------
You have 8 guesses left.
Your guess: a There are no A's in the word. The word now looks like this: -------- You have 7 guesses left. Your guess: e That guess is correct. The word now looks like this: ------E- You have 7 guesses left. Your guess: i There are no I's in the word. The word now looks like this: ------E- You have 6 guesses left. Your guess: o That guess is correct. The word now looks like this: -O----E- You have 6 guesses left. Your guess: u That guess is correct. The word now looks like this: -O--U-E- You have 6 guesses left. Your guess: s There are no S's in the word. The word now looks like this: -O--U-E- You have 5 guesses left. Your guess: t That guess is correct. The word now looks like this: -O--UTE- You have 5 guesses left. Your guess: r That guess is correct. The word now looks like this: -O--UTER You have 5 guesses left. Your guess: c That guess is correct. The word now looks like this: CO--UTER You have 5 guesses left. Your guess: m That guess is correct. The word now looks like this: COM-UTER You have 5 guesses left. Your guess: p That guess is correct. You guessed the word: COMPUTER You win. Play another round of Hangman (y/n)? n

Part 2: Implementation Details

Your program must be able to

Think first about what the overall structure of the program is and how to break the program down into separate methods. Figure out what variables you will need and how information flows back and forth between the different methods that make up the complete solution.

Your program should implement the following features:

Style Guidelines

To show you one possible implementation, we have provided some skeleton classes to get you started. These classes can be found at the here. Note that these classes are incomplete.It is strongly encouraged that you first conduct your design before looking at the sample skeleton classes. You may feel that your design is better and we courage that you use your own design.


Part 3. Submitting Your Assignment

Please submit electronically for assignment #7 and make sure you submit (1) Hangman.java. Please be sure that you choose the .java file, NOT the .class file when uploading. The .class file is the compiled version of your code which we cannot examine and grade. So, please make sure you submit *.java files. Also, remember that you always need to include the header.


    //*******************************************************************
    //
    //   File: FileName.java          Assignment No.: 7
    //
    //   Author: <your name>      Email: <your email>
    //
    //   Class: ClassName
    // 
    //   Time spent on this problem: 
    //   --------------------
    //      Please give a description about your design. 
    //
    //*******************************************************************

The submission repository for ps7 is https://gitee.com/simmonsong/ct-xmuf25-ps7.

Please follow the instructions in Assignments Submission to submit your assignments.

Git introduction is a help document for git utilization..

Enjoy!


Some part of the problem set derived from Building Java Programs.