Java代写|OOP编程|算法设计-CMSC131Object-Oriented Programming

Java代写|OOP编程|算法设计:这是一个通过java进行OOP面向对象编程的联系project

CMSC131 – Object-Oriented Programming I

1 Overview

For this project you will implement the classic game of Hangman in Java. The main objective of this project isto reinforce your understanding of the String.

Use Eclipse to work on this project. Check out first theHangmanproject from the CVS repository and thenwrite code in the provided methods. You may add more methods if you need, but you are not allowed to modifythe provided method signatures in the starter file. The methods will be called from themainmethod.

2 Requirements

The flow of the game is given blow. You must implement the features described in the flow and must alsoconsider the constraints for each step in the flow in your implementation.

  1. At start, your program will first call thechooseWordmethod that selects a word from a text file andreturns the word selected (i.e., a String is returned from the method). This method is already implementedin the starter code. You must NOT modify the method but instead will call it from themainmethod orfrom a method you create. ThechooseWordmethod takes two parameters. When you call the method, usefandrand(already initialized in themainmethod) as the parameters.The word selected from thechooseWordmethod should be validated by calling theisValidWordmethod,which returns,falseif the word does not satisfy any of the following constraints:- No alphabet occurs three or more times (e.g.,sadnessis invalid).- At least 6 alphabets in the word (e.g.,enjoyis invalid).- Only alphabets in the word (e.g.,bona fideis invalid).
The selection-validation process should be repeated until a word satisfying the constraints is selected.
  1. After a secret word is selected, your program will display a prompt message for a game mode. The playerwill enter either i (or I) for thecase insensitivemode or s (or S) for thecase sensitivemode. Then theplayer will type the enter key to start to game. The following shows an example interaction with theplayer in the console. In the example, the player chooses the case insensitive mode. (We will use this modein the running example.) If the player enters any other key (e.g., k), repeat displaying the prompt againand receive the user input.
Choose the game mode i/I for case insensitive mode, s/S for case sensitive mode): i
You selected case insensitive mode.
  1. The program will then display a prompt message to receive a guess from the player. It will display theselected word in console by a row of underscore characters, where each underscore character representseach letter of the word (say thishidden word). Now, the program is ready to interact with the player. Forexample, if the word ispractice(7 unique alphabets),
________ 10 Remaining guesses
Enter a letter or string:
  1. If the guessing player enters a letter or a string, followed by an enter key,
(a) If the letter or string occurs in the word, your program shows it in all its correct positions. In specific,
the program prints one more line that reveals the correct letter(s) or string(s). Set the initial number
of guesses to 3 more than the number of unique alphabets in the selected word. For example, if the
word ispractice(7 unique alphabets) and the player first entersice, the following message should be
printed:
_____ice 10 Remaining guesses
Enter a letter or string:
In this example, the number of guesses left is unchanged becauseiceoccurs in the word. When you
write code that prints the messages, put 3 space characters between the word and the remaining guess
message, and put a space after : in the second line. Note that this example assumes the
case-insensitive mode. Even though the player entersICE, the output message should be identical.
The second line will only be displayed if the word is not fully revealed after the guess.
(b) If the suggested letter or string does not occur in the word, the number of allowed guesses will be
decreased by 1. In the example above, if the player first entersk, the following message should be
printed:
k does not occur in the word.
________ 9 Remaining guesses
Enter a letter or string:
  1. Repeat the step 3 and 4 until all alphabets of the word is fully revealed or until the number of allowedguesses is decreased to 0.
  2. If all guesses are used up and the word is still not fully revealed, display the following message. Again, theword we use in the example ispractice.
You lost! (The word was practice)
  1. If there are 0 or more remaining guesses and if the word is fully revealed, display a message.
Great! You saved the man!
  1. After the player uses up all guesses or the word is revealed, your program asks if the player wants to playagain. If the answer is yes, the game begins again. Otherwise, the game ends. Use the following messages:
Do you want to play again? (y/n):
The player will enter y (or Y) for another game, or n (or N) to end the game. Again, put a space after
: in the message. If the player wants to play another game, repeat the flow from the step 1. If the player
enters any other key (e.g., k), repeat displaying the prompt again and receive the user input.
Invalid command. Do you want to play again? (y/n):

3 Grading and Good Faith Attempt Policy

Your submission will be evaluated based on the public, release, and secret tests in the submit server. All publictests must be passed to meet the GFA requirements for this project.

4 Example

An example output from a fully implemented project is given below for your reference.

Choose the game mode i/I for case insensitive mode, s/S for case sensitive mode):iYou selected case insensitive mode.______ 8 remaining guesses.Enter a letter or string: tt_ 8 remaining guesses.Enter a letter or string: iti 8 remaining guesses.Enter a letter or string: oo_tio_ 8 remaining guesses.Enter a letter or string: poptio_ 8 remaining guesses.Enter a letter or string: nGreat! You saved the man!(The word wasoption)Do you want to play again? (y/n):n

Another execution example output is given below.

Choose the game mode i/I for case insensitive mode, s/S for case sensitive mode):sYou selected case sensitive mode.______ 8 remaining guesses.Enter a letter or string: OO does not occur in the word.______ 7 remaining guesses.Enter a letter or string: p_p____ 7 remaining guesses.Enter a letter or string: n_p___n 7 remaining guesses.Enter a letter or string: II does not occur in the word._p___n 6 remaining guesses.Enter a letter or string: KK does not occur in the word._p___n 5 remaining guesses.Enter a letter or string: OO does not occur in the word._p___n 4 remaining guesses.Enter a letter or string: oop__on 4 remaining guesses.Enter a letter or string: TT does not occur in the word.op__on 3 remaining guesses.Enter a letter or string: topt_on 3 remaining guesses.Enter a letter or string: LL does not occur in the word.opt_on 2 remaining guesses.Enter a letter or string:EE does not occur in the word.opt_on 1 remaining guesses.Enter a letter or string: ee does not occur in the word.You lost! (The word was option)Do you want to play again? (y/n):n

5 Requirements on readability and coding style

Follow a good coding style (e.g.,http://www.cs.umd.edu/~nelson/classes/resources/javastyleguide/, sec-tions 14, 16, and 18 can be ignored). Your code should be properly indented (use the AutoFormat feature inEclipse), and well documented with appropriate comments. It is mandatory to use meaningful variable names,rather than magic numbers (literal constants). There are no explicit requirements for how many and what typeof variables. For readability including variable naming, we suggest you to use these rules:

  • Format the code clearly with blank lines, spacing and indents
  • Use self-documenting, meaningful variable names
  • Use variable names that begin with lower case and then camel case (e.g., roomTemp) if two words
  • Use capital letters (e.g., ALLCAPS) for variables that encodes constant values that arent updated
  • Use appropriate comments that indicate what a section, or a complicated line, does

As you have done for other projects, first few lines of your code should be the comments with the project, date,and author (you) information. You arerequiredto write your name, directory ID, university ID, and sectionnumber as a comment at the top of each file you submit from this project forward. Additionally, we expect youto write the honor pledge (I pledge on my honor that I have not given or received any unauthorizedassistance on this assignment/examination.) as a comment near the top of each file you submit.

6 Submission

Submit your work to P3 in the submit server by the due date/time (Check the submit server). It is stronglyrecommended to submit directly using the Submit Project menu in Eclipse. After submission, check in thesubmit server that your work is submitted correctly and also that your code passed all tests. Note that you willneed to pass all release/secret tests to get the full credits.

7 Extra point (20 points) Hangman in Processing

What you have developed in this project is a text based game. For extra credits, create a separate, visual versionof Hangman in Processing. The Processing version cannot be claimed as a substitute submission of the mainproject (in Java, using Eclipse) implementation expected. For submission, compress all files needed to run yourcode into a zip file and submit the compressed file toP4Extrain the submit server. The best submission will begiven a separate prize announced after the project deadline.

8 Academic Integrity

Make sure you read the academic integrity section of the syllabus so you understand what you must not do. Notethat we check your submission against other students submissions, and that we are required to report academicdishonesty cases to the Universitys Office of Student Conduct. As stated in section 2, you arerequiredto writethe honor pledge as a comment near the top of each file you submit.

发表评论

电子邮件地址不会被公开。 必填项已用*标注