Java Reference
In-Depth Information
Total points possible for exercise 3:
8
Your total is 22 out of 30, or 73.33%.
10. The game of Pig is a simple two-player dice game in which the first player to
reach 100 or more points wins. Players take turns. On each turn, a player rolls a
six-sided die:
If the player rolls a 1, then the player gets no new points and it becomes the other
player's turn.
If the player rolls 2 through 6, then he or she can either
ROLL AGAIN or
HOLD. At this point, the sum of all rolls is added to the player's score and it
becomes the other player's turn.
Write a program that plays the game of Pig, where one player is a human and the
other is the computer. When it is the human's turn, the program should show the
score of both players and the previous roll. Allow the human to input “r” to roll
again or “h” to hold.
The computer program should play according to the following rule:
Keep rolling when it is the computer's turn until it has accumulated 20 or
more points, then hold. If the computer wins or rolls a 1, then the turn ends
immediately.
Allow the human to roll first.
11. You have three identical prizes to give away and a pool of 30 finalists. The finalists
are assigned numbers from 1 to 30. Write a program to randomly select the num-
bers of three finalists to receive a prize. Make sure not to pick the same number
twice. For example, picking finalists 3, 15, 29 would be valid but picking 3, 3, 31
would be invalid because finalist number 3 is listed twice and 31 is not a valid
finalist number.
12. Redo or do for the first time Programming Project 2.13 from Chapter 2 but this
time use a loop to read the names from the file. Your program should also handle
an arbitrary number of entries in the file instead of handling only three entries.
To do this, your program must check to see if there is still data left to read (i.e., it
has reached the end of the file). The appropriate methods to read from a file are
described in Section 2.3 .
13. The file words.txt on the topic's website contains 87,314 words from the English
language. Write a program that reads through this file and finds the longest word
that is a palindrome.
14. The file words.txt on the topic's website contains 87,314 words from the English
language. Write a program that reads through this file and finds the word that
has the most consecutive vowels. For example, the word "bedouin" has three
consecutive vowels.
VideoNote
Solution to
Programming
Project 3.13
Search WWH ::




Custom Search