h2leen
March 17th, 2008, 09:04 AM
Hi everyone
Hi
I have a simple homework in JAVA programming and really i need your help to do it corectly. because this is the first time i use java in programming.
Please my friends help me .
the Q description :
The ‘COW’ Game
Introduction
Your task is to produce a Java program, which will implement a game called “The COW Game” and
allow users to try to guess how quickly they can win the game.
Problem description
You will implement a game called “The COW Game”. The idea of the game is to guess the same random
string that the program has generated, and guess how many attempts it will take you to get it right.
For each game we create a random three character string, and at the start of each game the user
enters the number of attempts they think it will take them to win that particular game. Users will then
try to guess the sequence of the letters and on each consecutive guess receives a message indicating
how close their guess is to the correct String.
• A “W” indicates that they don’t have any characters right.
• One or more “O”s indicates that they have a correct character/s, but in the incorrect position/s.
• Finally, one or more “C”s indicates that they have the correct character/s in the correct position/s.
The following table gives an example of the game’s output for a user guess. Suppose the random string
is “ABC”.
UserGuess Output
EDF W
HGB O
AHI C
AHB CO
CHJ O
BCG OO
CBA COO
ABC CCC
The second aspect of the game is how many points a user can earn when they guess the correct
string. If a user guesses the right answer in one turn, they receive 10,000 points. The amount of points
they can get then decreases by 25% of its current value after each consecutive guess, until the user
either makes a correct guess OR the points they can get is less than 100 points. For instance if a user
was to guess correctly on their second guess they get 7,500 points (75% of 10,000), the third guess
5,620 points(75% of 7,500), and so on.
The third aspect of the game is a bonus awarded for correctly specifying how many guesses you thought
you would take to get the correct answer. If the user is correct in their estimate of how many turns it took
them to get the correct answer, they receive bonus points, based on the table below. For example, a
user thinks it will take them 6 guesses to find the correct solution and they do guess the right answer in 6
turns, they will receive a 2000 point bonus.
Number of Guesses Bonus Points
1-5 5000
6-10 2000
11-15 500
>15 0
When finishing a game, if user gets the whole string right (“CCC” outputted) before their possible points
drops below 100, they are told how many guesses it took them to figure out the correct sequence, and
how many points they have been awarded (including bonus points). If the user is unable to guess
correctly before their possible points drops below 100, they are told that the game is now over, the
number of incorrect guesses they made, and the correct solution.
The user will then have an option to play a new game if they wish. With each new game a new random
string is generated, and the user again inputs how many guess they think it will take them to find the
correct solution.
Program Requirements
Your program should consist of only one class (COWGame class) and only one method (the main
method). You will use a Terminal I/O interface and your program needs to display all information such
that it is easy to read. Your code also must be very well commented.
For each new game your program will generate three unique random numbers between 0 and 9
inclusive, and convert them into a String of three characters in the range A to J. This String will be an
input to a game, where the user tries to guess the correct letters in the correct order. Examples of valid
input Strings would be, “JAD”, “ABC”, “IBE” and “EFG”. Examples of some invalid input Strings could be
“abc”, “AAA”, “123”, “AdE” or “NME”.
When the program is first run, the user should be given a brief set of instructions on how to play the
game. Then the user should be asked for the number of attempts it will take them to find the correct
String. The amount of points the user can be awarded on their first guess is 10,000. The percentage that
their points will decrease each turn should be stored as a named constant (final double) with the name
PERCENT_DECREASE having a value of 0.25. This will be used to decrease the current possible points
after each incorrect guess.
Before the user makes each guess, the program needs to tell them the amount of points they can earn if
they guess correctly on this turn. When a user makes a guess of what they think the answer is, the
program needs to make a comparison between the user input String and the correct String generated by
the program, to see how close the user is to right answer. It should then give the user feedback based
on the problem description above. Note that the program should also handle invalid user input, and give
an appropriate error message on such input.
The program will continue on this basis until; either the user can only earn less than 100 points on their
next turn, or, the user makes a correct guess of the entire String.
• In the event that the user makes a correct guess, the program will give feedback as to how many
guess were made and what points they have earned. Note: that the program also needs to
evaluate what bonus, if any, the user has earned and add this amount to points earned.
• If the user is not able to guess correctly before their possible points earned drop below 100, the
program will tell them that the game is now over, the number of incorrect guesses that were
made, and tell the user the correct solution.
In both events, at the end of a game the program will prompt the user if they wish to play another game.
If they do, we start over, as if the program was running from the start again. If they wish to end, the
program should give an appropriate message before exiting.
Example
Here is a sample of how a sample run through how part of the program might look. It assumes that the
random sequence generated by the program for this game is “ABC”. Note: that the program output given
below is only designed as a guide, and can look different in your program.
Program Output: How many guesses do you think you will need?
User Input: 4
Program Output: You will receive 10,000 points if you guess the
right answer on the next attempt. Please input your guess.
User Input: IJS
Program Output: Invalid input, please try again
User Input: ECD
Program Output: Your guess was: ECD. Your clue is: O.
Program Output: You will receive 7,500 points if you guess the right
answer on the next attempt. Please input your guess.
User Input: DJH
Program Output: Your guess was: DJH. Your clue is: W.
Program Output: You will receive 5,625 points if you guess the right
answer on the next attempt. Please input your guess.
User Input: BEC
Program Output: Your guess was: BEC. Your clue is: CO.
Program Output: You will receive 4,218 points if you guess the right
answer on the next attempt. Please input your guess.
User Input: ABC
Program Output: Your guess was: ABC. You have guessed the right
answer! You did it in 4 guesses, and you’ve earned 9,218 points
for this game. You got a 5,000 point bonus for getting the answer
in the right number of guesses!
Program Output: Would you like to play another game (y/n)?
Hi
I have a simple homework in JAVA programming and really i need your help to do it corectly. because this is the first time i use java in programming.
Please my friends help me .
the Q description :
The ‘COW’ Game
Introduction
Your task is to produce a Java program, which will implement a game called “The COW Game” and
allow users to try to guess how quickly they can win the game.
Problem description
You will implement a game called “The COW Game”. The idea of the game is to guess the same random
string that the program has generated, and guess how many attempts it will take you to get it right.
For each game we create a random three character string, and at the start of each game the user
enters the number of attempts they think it will take them to win that particular game. Users will then
try to guess the sequence of the letters and on each consecutive guess receives a message indicating
how close their guess is to the correct String.
• A “W” indicates that they don’t have any characters right.
• One or more “O”s indicates that they have a correct character/s, but in the incorrect position/s.
• Finally, one or more “C”s indicates that they have the correct character/s in the correct position/s.
The following table gives an example of the game’s output for a user guess. Suppose the random string
is “ABC”.
UserGuess Output
EDF W
HGB O
AHI C
AHB CO
CHJ O
BCG OO
CBA COO
ABC CCC
The second aspect of the game is how many points a user can earn when they guess the correct
string. If a user guesses the right answer in one turn, they receive 10,000 points. The amount of points
they can get then decreases by 25% of its current value after each consecutive guess, until the user
either makes a correct guess OR the points they can get is less than 100 points. For instance if a user
was to guess correctly on their second guess they get 7,500 points (75% of 10,000), the third guess
5,620 points(75% of 7,500), and so on.
The third aspect of the game is a bonus awarded for correctly specifying how many guesses you thought
you would take to get the correct answer. If the user is correct in their estimate of how many turns it took
them to get the correct answer, they receive bonus points, based on the table below. For example, a
user thinks it will take them 6 guesses to find the correct solution and they do guess the right answer in 6
turns, they will receive a 2000 point bonus.
Number of Guesses Bonus Points
1-5 5000
6-10 2000
11-15 500
>15 0
When finishing a game, if user gets the whole string right (“CCC” outputted) before their possible points
drops below 100, they are told how many guesses it took them to figure out the correct sequence, and
how many points they have been awarded (including bonus points). If the user is unable to guess
correctly before their possible points drops below 100, they are told that the game is now over, the
number of incorrect guesses they made, and the correct solution.
The user will then have an option to play a new game if they wish. With each new game a new random
string is generated, and the user again inputs how many guess they think it will take them to find the
correct solution.
Program Requirements
Your program should consist of only one class (COWGame class) and only one method (the main
method). You will use a Terminal I/O interface and your program needs to display all information such
that it is easy to read. Your code also must be very well commented.
For each new game your program will generate three unique random numbers between 0 and 9
inclusive, and convert them into a String of three characters in the range A to J. This String will be an
input to a game, where the user tries to guess the correct letters in the correct order. Examples of valid
input Strings would be, “JAD”, “ABC”, “IBE” and “EFG”. Examples of some invalid input Strings could be
“abc”, “AAA”, “123”, “AdE” or “NME”.
When the program is first run, the user should be given a brief set of instructions on how to play the
game. Then the user should be asked for the number of attempts it will take them to find the correct
String. The amount of points the user can be awarded on their first guess is 10,000. The percentage that
their points will decrease each turn should be stored as a named constant (final double) with the name
PERCENT_DECREASE having a value of 0.25. This will be used to decrease the current possible points
after each incorrect guess.
Before the user makes each guess, the program needs to tell them the amount of points they can earn if
they guess correctly on this turn. When a user makes a guess of what they think the answer is, the
program needs to make a comparison between the user input String and the correct String generated by
the program, to see how close the user is to right answer. It should then give the user feedback based
on the problem description above. Note that the program should also handle invalid user input, and give
an appropriate error message on such input.
The program will continue on this basis until; either the user can only earn less than 100 points on their
next turn, or, the user makes a correct guess of the entire String.
• In the event that the user makes a correct guess, the program will give feedback as to how many
guess were made and what points they have earned. Note: that the program also needs to
evaluate what bonus, if any, the user has earned and add this amount to points earned.
• If the user is not able to guess correctly before their possible points earned drop below 100, the
program will tell them that the game is now over, the number of incorrect guesses that were
made, and tell the user the correct solution.
In both events, at the end of a game the program will prompt the user if they wish to play another game.
If they do, we start over, as if the program was running from the start again. If they wish to end, the
program should give an appropriate message before exiting.
Example
Here is a sample of how a sample run through how part of the program might look. It assumes that the
random sequence generated by the program for this game is “ABC”. Note: that the program output given
below is only designed as a guide, and can look different in your program.
Program Output: How many guesses do you think you will need?
User Input: 4
Program Output: You will receive 10,000 points if you guess the
right answer on the next attempt. Please input your guess.
User Input: IJS
Program Output: Invalid input, please try again
User Input: ECD
Program Output: Your guess was: ECD. Your clue is: O.
Program Output: You will receive 7,500 points if you guess the right
answer on the next attempt. Please input your guess.
User Input: DJH
Program Output: Your guess was: DJH. Your clue is: W.
Program Output: You will receive 5,625 points if you guess the right
answer on the next attempt. Please input your guess.
User Input: BEC
Program Output: Your guess was: BEC. Your clue is: CO.
Program Output: You will receive 4,218 points if you guess the right
answer on the next attempt. Please input your guess.
User Input: ABC
Program Output: Your guess was: ABC. You have guessed the right
answer! You did it in 4 guesses, and you’ve earned 9,218 points
for this game. You got a 5,000 point bonus for getting the answer
in the right number of guesses!
Program Output: Would you like to play another game (y/n)?