I need an algorithm class and main method class for the foll
I need an algorithm, class, and main method class for the following please:
Consider a class that could be used to play a game of hangman. The class has the following attributes: • The secret word • The disguised word, in which each unknown letter in the secret word is replaced with a question mark (?). For example, if the secret word is abracadabra, and the letters a , and b have been guessed, the disguised word would be ab?a?a?ab?a • The number of guesses made • The number of incorrect guesses It will have the following methods: • MakeGuess(c) guesses that character c is in the word • getDisguisedWord returns a string containing correctly guessed letters in their correct positions and unknown letters replaced with ? • getSecretWord returns the secret word • getGuessCount returns the number of guesses made • isFound returns true if the hidden word has been discovered. Perform the following actions: • Write a method heading for each method. • Write preconditions and postconditions for each method. • Write some Java statements that test the class. • Implement the class. • List any additional methods and attributes needed in the implementation that were not listed in the original design. List any other changes made to the original design. • Write a program that implements the game of handgman, using the class you wrote for part d.
Solution
public class main { private int length; private String word; private String result; private String buffer; public main(String aword) { result = \"\"; word = aword; length = word.length(); buffer = \"\"; } public String guess(String aguess) { for(int i = 0; i < length; i++) { buffer = aguess.substring(i, i+1); if(word.indexOf(buffer) == i) result = result + buffer; else if ((word.indexOf(buffer) != -1)) result = result + \"+\"; if ((word.indexOf(buffer) == -1)) result = result + \"*\"; } return result; } }