Display the contents of the players array

Assignment Help JAVA Programming
Reference no: EM131880940

Programming Assignment

1. Getting Started

In this assignment, you will be writing a word game that makes use of arrays and static methods. A class called WordList has been posted along with this assignment. You will be using a method in this class for generating a random word. Download WordList.java to the same folder as your code. You may need to refresh the folder for the file to appear in Eclipse: select the folder and either press the F5 function key or select File > Refresh from the menu. Do NOT make any changes to this class and do NOT submit it. Only submit your Hangman program.

2. Programming Assignment

Hangman

In this game, one player (Player A) picks a word and lets the other player (Player B) know how many letters are in it by drawing a template in which each letter is represented by a dash. Player B then guesses one letter at a time. If the letter is in the word, Player A writes it into the template in however many places that it appears. Player B continues to guess until either the number of allowed guesses runs out or the correct word has been guessed.

In the version you will be writing, the program will display a template in which all letters in the word to be guessed originally appear as dashes ('-'). After a correct guess by the player, the program will update the template by filling in all occurrences of that letter. If the guess is incorrect, a message stating "Incorrect" will be printed. The program will also list, in alphabetic order, all incorrect guesses so far if there are any. This will be followed by the template being printed. Prompting for another letter will continue until (1) the player has guessed the word correctly, in which case a message including the word "congratulations" will be displayed, or (2) the player has used up the allowed maximum of six incorrect guesses, in which case a message that includes the words "game over" will be displayed along with the correct word. In the following sample interactions, player input appears in bold:

Be sure to read through the entire set of requirements assignment before beginning.

Basic code requirements:

1. The player is allowed a maximum of six incorrect guesses. Store this value to a named constant. If the player has used up all incorrect guesses, the player has lost and the game ends. The player wins if the word is guessed prior to having amassed six incorrect guesses.

2. You must use a minimum of two arrays of type char in completing this assignment. One will store the letters in the word being guessed (wordToGuess below). The other will store the letters that the player has guessed correctly (playerGuess below).

• To generate a word for the player to guess, you will be invoking the static getWord() method from the WordList class, which will return a pseudorandomly selected word as an array of type char. Initially, it is recommended that you do not call this method from your code. Instead, initialize the array yourself so that you can test repeatedly with the same word until the code is working correctly. For example, you could start with:

char[] wordToGuess = {'e','f','f','e','c','t'};

When you are satisfied that your code is correct, replace the hardcoded array with the call to the the getWord() method from the WordList class. DO NOT copy this method into your code.

• The playerGuess array must be initialized with dashes (i.e., char values of '-­-').

• After prompting the player to enter a letter, use the charAt() method in conjunction with the next() method for getting the first character in the player's input.

• If the player has correctly guessed a letter, replace the dash(es) in the corresponding position(s) in the playerGuess array with the lowercase value of that letter. For example, given the letters stored to the wordToGuess array shown above, if the player's first guess is the letter ‘f', then the playerGuess array should be updated to contain {'-­-', 'f', 'f', '-­-', '-­-', '-­-'}.

• After an incorrect guess, display a message including the word "incorrect" (see additional requirements for listing all incorrect guesses and verifying input; it is recommended that you get this basic functionality working first).

• Display the contents of the player's array, regardless of whether the template has been updated.

• If the player has won, display a message including the word "congratulations." If the player has lost, include the word "over" in your message and print the word being guessed.

Additional requirements: static methods and input verification. Note: you are not limited to defining and using only the two methods specified below; this is a minimum requirement.

After getting the basic logic described above to work, add the following methods and functionality:

1. Define a static method with the following return type and signature:

char[] fillArray(char, int)

This method returns a new char array whose elements are set to the value of the first parameter and whose size is set to the value of the second parameter. For example, if passed the char '?' and the integer 5, the new array to be returned by this method would contain: {'?','?','?','?','?'}.

Use this method to create the player's array and initialize its contents to dashes.

2. Verify that the player has entered a letter (see the Character methods in section 4.3.4 of the textbook). If the input is not a letter, inform the player of this, using the word "not" in your error message. Then reprompt until a letter has been entered. Invalid guesses do not count as incorrect. See sample output 3.

3. If the player has entered a letter, store it in lowercase (see section 4.3) to make your code case-­- insensitive (note that all of the words in the WordList class contain only lowercase letters).

4. If a letter has already been guessed, the player must be informed of this, with the word "before" included in your message. A repeated guess does not count as incorrect. See sample output 3. An additional array would be helpful here, and an additional method may be as well.

5. Display the list of incorrect guesses after any valid input, with each letter except for the last one in the list followed by a comma and a space (", ") as shown in the sample outputs. If the guess is incorrect, the list must come after the message informing the user of this. For full credit, display the list in alphabetical order. You may want to write a method to provide this functionality.

6. Define a static method with the following return type and signature:

replaceChar boolean (char, char[], char[])

This method first checks if the two arrays passed as arguments are of the same size. If they are the same, it searches for each occurrence of the value passed to the first parameter in the array passed to the second parameter. Each time it is found, that value is added to the same position in the array passed to the third parameter. For example,

if passed: 'a', {'b','a','n','a','n','a'}, {'b','-­-','-­-','-­-','-­-','-­-'}
then the contents of the second array will be updated to: {'b','a','-­-','a','-­-','a'}

A value of true is returned if any replacements have been made. If the second array is unchanged, a value of false is returned (note that if the arrays are of different sizes, no replacements will be made and the value returned will be false). Use this method to check if a guess is correct and to update the player's array with the correctly guessed letter.

Attachment:- Wordlist.rar

Reference no: EM131880940

Questions Cloud

Return on each stock-what is the return on portfolio : What is the return on each stock? The return on market is 14.8 percent and there are no unsystematic surprises in returns. What is return on portfolio?
What is the economic order quantity : When ordered, the setup cost to produce an order is $600, and the production process is able to produce 500 per week and deliver them weekly as produced.
What are the lower and upper bounds of confidence interval : If the average of a sample size of 250 measures is $4 million and the standard deviation of the sample is $900000 what are the lower and upper bounds.
Explain different types of contingent liabilities : When should a business expense employee vacation compensation? How do we account for each of the 3 different types of contingent liabilities?
Display the contents of the players array : Programming Assignment. Display the contents of the player's array, regardless of whether the template has been updated.
Current profit margin and pro forma profit margin : By what percentage did your net income change? What are your current profit margin and your pro forma profit margin?
What is the journal entry and adjusting journal entry : April 21st, your customers bought 15,000 units of your product for $115 per unit (you decide what your company sells).
Calculate present value and future value : And how would you calculate Present Value and Future Value from there?
Define steps for a periodic inventory system : What are the three steps that must take place to obtain enough information for a periodic inventory system.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a test application named simpledatetest

Write a test application named SimpleDateTest that demonstrates class SimpleDate's capabilities

  The waiting state in java programming

Which is the way in which a thread can enter the waiting state in java programming?

  Implement elliptic curve encryption - decryption in java

Implement Elliptic Curve encryption - decryption in java. Specifically, your program will read parameters, plaintext and ciphertextfrom a file

  Locate the errors in the following code

Locate the errors in the following code

  What is the difference between arrays and arraylist

What is the difference between arrays and ArrayList? What are the advantages and disadvantages of an ArrayList

  Create a class called author

Create a class called Author is designed as follows: Three private instance variables: name (String), email (String), and gender (char of either ‘m' or ‘f'); One constructor to initialize the name, email and gender with the given values

  Calculate the amount due for hamburger

Harry from Harry's Hamburger Hut sells custom hamburgers. He wants you to write a program to calculate the Amount due for Hamburger.

  How do you arrange passenger on flight sits

Millions of commercial airline flights cross the world's cities every year, and each one of these flights must solve what seems like a simple problem: how do you arrange where each passenger on one of those flights sits

  When would you use a looping statement

Java provides three repetitions structures: while, do while and for. These statements are also known as loops. When would you use a looping statement?

  What will be displayed by the method call recurse

What will be displayed by the method call recurse(1234)? Which of the following problems would be a good candidate for using a stack? Which of the following is correct to sort the elements in a list aList?

  Create a java class that contains

Create a java class that contains A two-argument constructor that creates a CdPlayer object with specified manufacturer name and color.

  Draw a uml diagram of each of the shapes

Draw a UML diagram of each of the Shapes, Rectangle and Square classes using the code that has been provided. Complete this using the examples that have been provide in the lecture slides.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd