Question
Hangman Java Code Reflection: I would like to have a reflection written upon the java code hangman game program located below as if you are
Hangman Java Code Reflection: I would like to have a reflection written upon the java code hangman game program located below as if you are preparing to write and have written the code. Such as what the project's tasks are in order to complete the program, and the workflow you would use. How would your pseudocode look to plan the program out? How would your workflow look, and what lessons would you perhaps learn trying it the first time.Please no one or two sentence responses. I need a thorough reflection. Thank you for your time.
import java.util.*; class Hangman { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in);
int noOfGuesses =0,lettersCorrect=0; String choiceToPlay, userGuess; char menuChoice, letter; char [] guessWord = {'h', 'e', 'l', 'l', 'o'}; char [] correctLetter = {'-', '-', '-', '-', '-'};
System.out.println("Hello and welcome to Hangman!");
//main game menu do { System.out.println("Do you want to play? Press Y/N "); choiceToPlay = keyboard.next(); menuChoice = choiceToPlay.charAt(0);
if(!(menuChoice == 'y'||menuChoice == 'Y'||menuChoice == 'n'||menuChoice =='N')) { System.out.println("You have entered an invalid option. Try again! "); }//if invalid
}//do while (!(menuChoice =='Y' ||menuChoice=='y'||menuChoice == 'n'|| menuChoice =='N'));
if(menuChoice == 'N'||menuChoice =='n') { System.out.println("You have chosen to leave the game."); System.out.println("Goodbye!"); System.exit(0); }//if
else {
while(lettersCorrect <5) { //Getting users guess. System.out.println(" The guess word has 5 letters."); System.out.println("Enter a letter to guess: ");
userGuess = keyboard.next(); letter = userGuess.charAt(0);
//Incrementing letters each time. noOfGuesses++;
if(letter == guessWord[0]) { System.out.println("There is 1 H in the word"); System.out.println("You have guessed the first letter correctly."); correctLetter[0] = letter; System.out.println(correctLetter); System.out.println("You have had " + noOfGuesses + " guesses, so far");
lettersCorrect++;
System.out.println("Letters correct so far: "+lettersCorrect); }//if first letter
else if(letter==guessWord[1]) { System.out.println("There is 1 E in the word"); System.out.println("You have guessed the second letter correctly.");
correctLetter[1] = letter; System.out.println(correctLetter); System.out.println("You have had " + noOfGuesses + " guesses, so far");
lettersCorrect++;
System.out.println("Letters correct so far: "+lettersCorrect); }//if second letter
else if(letter ==guessWord[2]||letter==guessWord[3]) { System.out.println("There are 2 L's in the word"); System.out.println("You have guessed the third and fourth letters correctly.");
correctLetter[2] = letter; correctLetter[3]=letter; System.out.println(correctLetter); System.out.println("You have had " + noOfGuesses + " guesses, so far");
lettersCorrect+=2;
System.out.println("Letters correct so far: "+lettersCorrect);
}//if third and fourth letters
else if(letter ==guessWord[4]) { lettersCorrect++; System.out.println("There is 1 O in the word"); System.out.println("You have guessed the fifth letter correctly."); correctLetter[4] = letter; System.out.println(correctLetter); System.out.println("You have had " + noOfGuesses + " guesses, so far"); System.out.println("Letters correct so far: "+lettersCorrect); }//if fifth letter
else { System.out.println("The letter you guessed is not in the word. "); System.out.println("Guesses taken so far: "+noOfGuesses); System.out.println("Letters correct so far: "+lettersCorrect); }//else incorrect letter
}//while loop
System.out.println(" You found the word!"); System.out.println("It was hello."); System.out.println("Total guesses: "+noOfGuesses); System.exit(0);
}//else }//main }//class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started