The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 3 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
I need help with my JAVA program with code. I just need help implementing 3 methods (isComplete, foundGuessLetter, pickedRandomWord). The main method on the bottom doesn't need to be changed. I commented where exactly I need help implementing at. Thanks!
import java.util.Scanner;
public class Hangman {
 Â
/** We'll use underscores for unknown letters. */
public static final char BLANK = '_';
/**
  * Have all the letters in the guess been filled in?
  * @param knownLetters Array of letters that player knows.
  * @return True if knownLetters has no blanks (that is, no underscores)
  */
public static boolean isComplete(char[] knownLetters) {
// REPLACE THE METHOD BODY
return false;
}
/**
  * Checks to see if letter occurs at least once in word. If so,
  * sets the corresponding elements of knownLetters to letter and
  * returns true. If not, returns false.
  * @param letter Letter that player has guessed.
  * @param word The word we are checking.
  * @param knownLetters Array of letters that player knows.
  * @return True if letter was found in word.
  */
public static boolean foundGuessedLetter(char letter,
  String word,
  char[] knownLetters) {
// REPLACE THE METHOD BODY
return false;
}
/**
  * Selects a random word from the dictionary.
  * @param dictionary An array of words.
  * @return Randomly chosen word from dictionary.
  */
public static String pickRandomWord(String[] dictionary) {
// REPLACE THE METHOD BODY
// Maybe implementing this method first, since
// the program will crash if it returns null.
return null;
}
/**
  * This method prints ASCII art of the hanged man.
  * You don't need to change this method.
  * @param guesses The number of guesses remaining.
  */
public static void drawAsciiMan(int guesses){
// top of gallows
System.out.println(" _______");
// head (or not)
if(guesses < 6) {
System.out.println(" | O");
} else {
System.out.println(" |");
}
// Body and arms
switch (guesses) {
case 6:
case 5:
// no body
System.out.println(" |");
break;
case 4:
// body, no arms
System.out.println(" | |");
break;
case 3:
// body and left arm
System.out.println(" | /|");
break;
default:
// body and both arms
System.out.println(" | /|\\");
break;
}
// Legs
switch (guesses) {
case 1:
// left leg
System.out.println(" | /");
break;
case 0:
// both legs
System.out.println(" | / \\");
break;
default:
// no legs
System.out.println(" |");
break;
}
// bottom of gallows
System.out.println("_|_" );
}
/**
  * Plays a text-based game of hangman.
  * You don't need to change this method.
  */
public static void main(String[] args) {
// Let's use some animals for our words in this game.
String[] words = {"aardvark", "alligator", "alpaca", "anteater",
"antelope", "ape", "armadillo", "baboon",
"badger", "bat", "bear", "beaver", "bison", "boar",
"buffalo", "bull", "bunny", "burro", "camel",
"canary", "capybara", "cat", "chameleon", "cheetah",
"chimpanzee", "chinchilla", "chipmunk", "colt",
"cougar", "cow", "coyote", "crocodile", "crow",
"deer", "dingo", "doe", "dog", "donkey", "dormouse",
"elephant", "elk", "ewe", "fawn", "ferret", "finch",
"fish", "fox", "frog", "gazelle", "giraffe", "gnu",
"goat", "gopher", "gorilla", "hamster", "hare",
"hedgehog", "hippopotamus", "hog", "horse", "hyena",
"ibex", "iguana", "impala", "jackal", "jaguar",
"kangaroo", "kid", "kitten", "koala", "lamb",
"lemur", "leopard", "lion", "lizard", "llama",
"lynx", "mare", "marmoset", "marten", "mink",
"mole", "mongoose", "monkey", "moose", "mouse",
"mule", "muskrat", "mustang", "newt", "ocelot",
"opossum", "orangutan", "oryx", "otter", "ox",
"panda", "panther", "parakeet", "parrot", "pig",
"platypus", "pony", "porcupine", "porpoise", "puma",
"puppy", "rabbit", "raccoon", "ram", "rat",
"reindeer", "reptile", "rhinoceros", "salamander",
"seal", "sheep", "shrew", "skunk", "sloth", "snake",
"squirrel", "stallion", "steer", "tapir", "tiger",
"toad", "turtle", "vicuna", "walrus", "warthog",
"weasel", "whale", "wildcat", "wolf", "wolverine",
"wombat", "woodchuck", "yak", "zebra"};
 Â
System.out.println("Welcome to Hangman! Try to guess my word.");
String word = pickRandomWord(words);
 Â
char[] known = new char[word.length()];
for(int i = 0; i < known.length; i++) {
known[i] = BLANK;
}
Scanner sc = new Scanner(System.in);
int guesses = 6;
while(guesses > 0 && !isComplete(known)) {
System.out.println(); // blank line between guesses
System.out.println("Guesses remaining: " + guesses);
drawAsciiMan(guesses);
System.out.println("Word: " + new String(known));
System.out.print("Enter your guess: ");
// grabbing the entire next token and then taking only 1st char
char letter = sc.next().trim().charAt(0);
if(!foundGuessedLetter(letter, word, known)) {
System.out.println("Sorry, there is no " + letter);
guesses--;
}
}
drawAsciiMan(guesses);
System.out.println("Word: " + new String(known));
if(isComplete(known)) {
System.out.println("Hooray! You win!");
} else {
System.out.println("You lose. The word was: " + word);
}
}
}
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll