Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could someone write the WordHider class in JAVA? I have the dictionary class alr

ID: 3575017 • Letter: C

Question

Could someone write the WordHider class in JAVA? I have the dictionary class already written but cannot get the WordHider class figured out. I have provided the description of what the class needs to do.

[URL=http://s1330.photobucket.com/user/PushedCrayon/media/Java_zpshqnq3bfi.png.html][IMG]http://i1330.photobucket.com/albums/w566/PushedCrayon/Java_zpshqnq3bfi.png[/IMG][/URL]

Class WordHider: This class has hiddenWord that holds the word that needs to be revealed, and partiallyFoundWord, that stores the ‘hidden’ version of hiddenWord by starting out as a set of asterisks and adding the letters of hiddenWord as they are revealed. The getters and setters have not been listed, but make sure you do not create a setter for partiallyFoundWord because it is only used by the class to represent the part of hiddenWord that has been revealed. Method revealLetter() takes a String that should have only character and reveals that letter however many times it appears in the word. If the String parameter holds more or less than 1 character, it reveals no letters. This method should return how many letters were revealed in the word. Method wordFound() returns true if partiallyFoundWord contains no asterisks (the whole word has been revealed), false otherwise. Method hideWord() resets partiallyFoundWord to all asterisks. Variable partiallyFoundWord must always be the same length as hiddenWord and can only contain asterisks, or letters that are the same value and position as hiddenWord.

Explanation / Answer

import java.util.Scanner;

public class HidWord {

        Scanner kb=new Scanner(System.in);

        String secretPhrase;

        String disguisedPhrase;

        String guess;

        int correctGuess,inCorrectGuess,totalGuess;

     

        //constructor, takes in a single argument the word to be guessed

    public HidWord( String newPhrase){

        secretPhrase=newPhrase;

        totalGuess++;

        }

     

    //method - version of word in the form of question form

        public void disguisedPhrase(){

        disguisedPhrase="";

        for(int i=0;i<secretPhrase.length();i++){

            disguisedPhrase+="?";}

                }

     

                public String getDisguisedPhrase(){return disguisedPhrase; }

        //public String toString(){return secretPhrase;}

         

        //determines if the character is in the word

        public void checkGuess(char letter){

                guess=kb.next().toLowerCase();

            letter=guess.charAt(0);

            char current;

            boolean guessCorrectly=false;

            for(int i=0; i<secretPhrase.length(); i++){

                current=secretPhrase.charAt(i);

                if (current==letter)

                {   guessCorrectly=true;

                if(i<secretPhrase.length())//check for rightness

                {  

                    disguisedPhrase=disguisedPhrase.substring(0,i)+current+disguisedPhrase.substring(i+1);}

                else

                {

                    disguisedPhrase=disguisedPhrase.substring(0,i)+current; }

                }

                }

            if(guessCorrectly)

            { correctGuess++; }

            else

            {inCorrectGuess++;}

                        }

         

                //method that check if the word is fully guessed or not

            public boolean isPhraseComplete(){

                    return disguisedPhrase.equalsIgnoreCase(secretPhrase);

                }

    //in this meth i want to collect letters and make guesses                  

            public void play(){

                while(!isPhraseComplete()==true)

                {      

                     

                System.out.println("The disguised word is: " +"<"+disguisedPhrase+">");

                System.out.println("Guess a letter: ");

                guess=kb.next().toLowerCase();

                 

                 

                //just for my self to check if user input all word

                if (guess.equals(secretPhrase)) {

                    System.out.println("The answer was: " + guess);

                    System.out.println("You WIN!");

                    break;

                } else {

                    System.out.println();

                    System.out.println(" " + disguisedPhrase);

                    }

                }

            }

                             

                         

        public static void main(String[] args)

        {

            System.out.println("lets play HiddenWord");

            HidWord test=new HidWord("happiness");

                 

            test.disguisedPhrase();

            //checkGuess(letter);

            test.play();

        }      

     }

import java.util.Scanner;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote