Question

In: Computer Science

1. Problem Description Based on the phenomenal success on previous projects, your angel investor has come...

1. Problem Description Based on the phenomenal success on previous projects, your angel investor has come back to your firm for yet another application. You are to develop a simple ‘Hangman’ game in which the computer selects a random word and the child repeatedly guesses letters until the word is uncovered. Sensitive to the tender age of our target audience, we will NOT draw a partially executed criminal but simply keep track of the number of guesses. There is no maximum number of guesses. With each successive guess, show the word with the correct letters filled in, and also all the letters that have been guessed so far. If the child guess the same letter more than once, do not count that guess against them. The guesses should be converted to upper case. Provide a set of at least ten words to guess from. The instructor’s example uses the words “one” through “ten”, however you are free to provide as many words as you would like. Keep track of the number of guesses the child takes and display this number at the end. Your application should only play the game once per execution (i.e. no “Would you like to play another game?” is required). 2. Notes • Turn in only your source files. 3. Required Main Class Hangman 4. Required Input A series of uppercase or lowercase letters 5. Required Output Your output should look something like the following example. Notice the multiple, repeated guesses (h and e). It must include your name. Hangman - E. Eckert _ _ _ _ _ Used letters: {} Enter a letter: a _ _ _ _ _ Used letters: {A} Enter a letter: b _ _ _ _ _ Used letters: {AB} Enter a letter: c _ _ _ _ _ Used letters: {ABC} Enter a letter: e _ _ _ E E Used letters: {ABCE} Enter a letter: t T _ _ E E Used letters: {ABCET} Enter a letter: h T H _ E E Used letters: {ABCETH} Enter a letter: h Enter a letter: e Enter a letter: r T H R E E Used letters: {ABCETHR} You guessed it in 7 tries.

Needs to be in java

Solutions

Expert Solution

Thanks for the question.

Below is the code you will be needing  Let me know if you have any doubts or if you need anything to change.

Thank You !!

===========================================================================

import java.util.Random;
import java.util.Scanner;

public class Hangman {

    private static Scanner scanner = new Scanner(System.in);


    public static void main(String[] args) {

        String words[] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
        String playAgain = "";
        do {


            String randomWord = words[new Random().nextInt(words.length)].toUpperCase();
            char[] randomWordLetters = randomWord.toCharArray();
            char[] matches = new char[randomWord.length()];
            boolean guessedIncorrect = true;
            char letter;
            int attempts = 0;
            System.out.println("\nHANGMAN");
            String guessedLetters = "";
            printArrayAndCompare(randomWordLetters, matches, guessedLetters);
            do {

                letter = getUserLetter();
                if (guessedLetters.contains(String.valueOf(letter))) {
                    continue;
                }
                guessedLetters += letter;
                attempts += 1;
                updateMatches(randomWordLetters, matches, letter);
                boolean flag = printArrayAndCompare(randomWordLetters, matches, guessedLetters);
                if (flag) {
                    System.out.println("You guessed it in " + attempts + " tries.");
                    guessedIncorrect = false;
                }
            } while (guessedIncorrect);
            System.out.print("Do you want to play again (yes/no)? ");
            playAgain = scanner.nextLine();
        } while (!playAgain.equalsIgnoreCase("no"));
    }


    private static boolean printArrayAndCompare(char[] wordLetter, char[] userLetter, String guessedLetters) {

        boolean flagComparison = true;
        for (int i = 0; i < userLetter.length; i++) {
            if (wordLetter[i] == userLetter[i])
                System.out.print(userLetter[i] + " ");
            else {
                System.out.print("- ");
                flagComparison = false;

            }
        }

        System.out.print("\tUsed letters: {" + guessedLetters + "}\n");
        return flagComparison;
    }

    private static void updateMatches(char[] randomWordLetters, char[] matches, char letter) {

        for (int index = 0; index < matches.length; index++) {
            if (randomWordLetters[index] == letter) {
                matches[index] = letter;
            }
        }
    }

    public static char getUserLetter() {

        String input = "";
        System.out.print("Enter a letter: ");
        input = scanner.nextLine().trim().toUpperCase();
        return input.charAt(0);
    }
}

===========================================================================


Related Solutions

An angel investor is interested in taking a stake in your business, be proactive and write...
An angel investor is interested in taking a stake in your business, be proactive and write a formal memo to your venture team on the information the angel investor would be interested in doing and say why
1. What is the difference between a VC and an Angel investor? 2. How are their...
1. What is the difference between a VC and an Angel investor? 2. How are their investment approached different? 3. According to Bussgang, what is the only number that matters to an entrepreneur in valuation and what is its equation? 4. Why does Bussgang call VC an “ADD” job and why is this important for the entrepreneur to understand when attempting to raise capital? 5. Identify the top 4 issues you would be concerned about when you are raising capital...
Scenario: You are an Angel Investor who has been approached by an entrepreneur to assess an...
Scenario: You are an Angel Investor who has been approached by an entrepreneur to assess an investment opportunity. An entrepreneur asks for $100,000 to purchase a diagnostic machine for a healthcare facility. The entrepreneur hopes to maintain as much equity in the company, yet the Angel Investor requires the transaction to be financed with 60% debt and 40% equity. As the Angel Investor, you assign a cost of equity of 16% and a cost of debt at 9%. Based on...
Scenario: You are an Angel Investor who has been approached by an entrepreneur to assess an...
Scenario: You are an Angel Investor who has been approached by an entrepreneur to assess an investment opportunity. An entrepreneur asks for $100,000 to purchase a diagnostic machine for a healthcare facility. The entrepreneur hopes to maintain as much equity in the company, yet the Angel Investor requires the transaction to be financed with 60% debt and 40% equity. As the Angel Investor, you assign a cost of equity of 16% and a cost of debt at 9%. Based on...
The ABC Company, a client of your firm, has come to you with the following problem....
The ABC Company, a client of your firm, has come to you with the following problem. it has three clerical employees who must perform the following functions: Maintain the general ledger Maintain the accounts receivable ledger Issue credits on returns and allowances Reconcile the bank account Handle and deposit cash receipts Assuming equal abilities among the three employees, the company asks you to assign the five functions to them to maximize internal control. Assume that these employees will perform no...
The Kernow Company, a client of your firm, has come to you with the following problem....
The Kernow Company, a client of your firm, has come to you with the following problem. It has three clerical employees who must perform these functions:             i)         Maintain general ledger             ii)        Maintain purchase (creditors) ledger             Iii)       Maintain sales (debtors) ledger             iv)       Prepare cheques for signature (including checking supporting documentation)             v)         Maintain expenses journal (recording expenses paid)             vi)       Issue sales credit notes             vii)      Reconcile bank statement             viii)     Handle and bank cash receipts....
The Kernow Company, a client of your firm, has come to you with the following problem....
The Kernow Company, a client of your firm, has come to you with the following problem. It has three clerical employees who must perform these functions:             i)          Maintain general ledger             ii)        Maintain purchase (creditors) ledger             Iii)       Maintain sales (debtors) ledger             iv)        Prepare cheques for signature (including checking supporting documentation)             v)         Maintain expenses journal (recording expenses paid)             vi)        Issue sales credit notes             vii)      Reconcile bank statement             viii)     Handle and bank cash receipts....
An entrepreneur has 2000 shares. An angel invested $1000 for 1000 shares.  A new investor would have...
An entrepreneur has 2000 shares. An angel invested $1000 for 1000 shares.  A new investor would have been willing to invest $500 for 1000 shares if there were no ratchet in the first round (a price of $0.50) per share. So the total value of the venture is $2000 and the new investor would own 25% of the value. At what price per share would the new investor be willing to invest if the first-round investor has a full ratchet?
Based on your success with minimum wage analysis in Assignment #5, the new administration now has...
Based on your success with minimum wage analysis in Assignment #5, the new administration now has a new study for you to conduct. With health care they are considering two alternatives: A system where health care is provided solely by the government (similar to what is in Canada) and another approach where government stays out of the health care market (except for assisting the poor who cannot afford it) and individuals buy health insurance from competing providers. Provide an economic...
You have decided that your company has outgrown the warehouse described in the previous problem. You...
You have decided that your company has outgrown the warehouse described in the previous problem. You have received an offer from someone willing to purchase the warehouse for $1,200,000. If you accept this offer, how much money will you have left over from the sale after you have paid off the balance of the loan? As a reminder, the original loan was a 15-year, 6% APR (monthly) loan with monthly payments with an original amount borrowed of $1,500,000. You have...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT