I need help the word class for a hangman program

here is the code i have so far:

/**
 * File: Word.java
 *
 */

package csc212project05;

import static java.lang.System.out;
import java.util.ArrayList;
import java.util.Scanner;

public class Word
{

    private static java.util.ArrayList<String> wordlist = null;
    private char[] lexeme = null; // the characters in the word

    /**
     * Build a list of words from file.
     * @param sc - connected to file containing word list
     * @global wordlist - this method adds content to wordlist
     */
    public static void initializeWordlist(Scanner sc)
    {
        wordlist = new java.util.ArrayList<String>();

        // FOR STUDENT TO COMPLETE
        // use a while loop to read all the words
        // from the Scanner object sc and add them to wordlist




    }

    /**
     * Construct a random Word object.
     * @global wordlist - copies a word from here
     */
    public Word()
    {
        // FOR STUDENT TO COMPLETE
        // select a random word from the wordlist (use the get method)
        // allocate a new char array to lexeme the length of this word
        // use a for loop to copy word.charAt(i) into lexeme[i]







    }

    /**
     * Construct a copy of a give Word object.
     * @param word - word to copy
     */
    public Word(Word word)
    {
        // FOR STUDENT TO COMPLETE
        // select a random word from the wordlist (use the get method)
        // allocate a new char array to lexeme the length of word.length()
        // use a for loop to copy word.lexeme[i] into lexeme[i]




    }

    /**
     * Construct a word of a given length repeating a single character.
     * @param ch - char to repeat
     * @param length - number of times to repeat ch
     */
    public Word(char ch, int length)
    {
        lexeme = new char[length];
        for (int j = 0; j < lexeme.length; j++) {
            lexeme[j] = ch;
        }
    }

    public int length()
    {
        return lexeme.length;
    }

    public String toString()
    {
        return new String(lexeme);
    }

    /**
     * Search for a matched character.
     * @return:  whether "copy" contains the char denoted by "guess"
     * @param guess the user's attempt at guessing a letter
     * @param disposableCopy a copy of secret word which we can destroy
     * @param whatWeHaveSoFar the part of the word we've solved so far
     */
    public static boolean matched(char guess,
                           Word whatWeHaveSoFar,
                           Word disposableCopy)
    {
        for (int i = 0; i < disposableCopy.lexeme.length; i++) {
            if ( guess == disposableCopy.lexeme[i] ) {
               whatWeHaveSoFar.lexeme[i] = guess;
               disposableCopy.lexeme[i] = '-';
               return true;
            }
        }
        return false;
    }

    /**
     * Does this Word object equal another Word object?
     * @return whether or not the contents in the two lexemes equal?
     */
    public boolean equals(Word otherWord)
    {
        // FOR STUDENT TO COMPLETE
        // if their lengths are unequal return false
        // else
        // write a for loop
        //     and compare lexeme[i] to otherWord.lexeme[i]
        //         if they are != return false








        // if you make it through the for loop return true
        return true;
    }


}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

i know i just have no clue how to do anything..im not asking for full code just maybe some hints if possible thanks

You are given plenty of hints in the code skeleton. Try to do some coding yourself and come back with more specific problems.

This article has been dead for over six months. Start a new discussion instead.