CSc 2310 Principles of Computer Programming I
Spring 1999
Programming Assignment #4
Due: 22 March 1999 (Monday)
A:> java Scores Enter exam scores one per line (enter 0 to quit): 63 75 72 72 78 67 80 63 75 90 89 43 59 99 82 12 100 0 Number of "A" scores = 3 Number of "B" scores = 3 Number of "C" scores = 5 Number of "D" scores = 3 Number of "F" scores = 3 ------------------------- Total Scores = 17 Average Score = 71 Maximum Score = 100 Minimum Score = 12
The main program should first display a Welcome Message explaining the rules of the games. Then, it should generate a 4-digit random number between 1000 and 9999 with no repeating digits. After that, it should repeatedly ask the user for his/her guess and report the BULLS and COWS for the guess compared with the random number. The game stops when either the player has made a correct guess or when the player had made 10 guesses.
You should make use of the class methods which you have written for the previous assignment. You will need two additional class methods:
public static int produceRandomTarget() public static void printWelcomeMessage()
The game interaction should look something like this:
Welcome to the game of BULLS and COWS.
The Objective in this game is for you to guess a 4-digit number
The computer responds with how close your guess is to the target
BULLS = # common digits with exact matches and
COWS = # common digits in wrong position.
1. Enter your guess: 1234
Bulls = 1 Cows = 0
2. Enter your guess: 8567
Bulls = 0 Cows = 1
3. Enter your guess: 1233
Your guess should not contain repeating digits
4. Enter your guess: 7654
Bulls = 0 Cows = 1
5. Enter your guess: 7642
Bulls = 0 Cows = 0
6. Enter your guess: 5913
Bulls = 1 Cows = 2
7. Enter your guess: 5091
Bulls = 2 Cows = 1
8. Enter your guess: 5039
Bulls = 4 Cows = 0
Congratulations; You Won!!
or a message saying that you lost and PRINT THE ACTUAL NUMBER.