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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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