41. Randomness - Link
- Task
- Answer
- Question
You know what’s cool? Having the computer randomly choose a number. This is the basis of pretty much every computer game ever.To pick a random number, you first need to Once that’s finished, you can have the computer pick a random integer like this:That’ll pick a random number from 1 to 10 (inclusive) and store it into the variable x. Enough of the explaining; let’s look at some code!Files Needed :Sample Output :Your random numbers will probably be different than these. Actually, that’s kind of the point.
import java.util.Random;.Then, you must create a random-number generator object, like so:42. Magic 8-Ball - Link
- Task
- Answer
- Question
43. A Number-Guessing Game - Link
- Task
- Answer
Modify your incredibly stupid number-guessing game to actually pick a random number from 1 to 10 and have the user try to guess that. Tell them if they get it right or wrong, and if they get it wrong, show them what the random number was.They will still only get one try.
Sample Output :
44. Fortune Cookie - Link
- Task
- Answer
Write a program that simulates a random fortune from a fortune cookie. You must have at least six fortunes.For bonus points, also add randomly-chosen lotto numbers to the fortune. In Texas, the lotto chooses 6 numbers, each from 1-54.
45. Dice - Link
- Task
- Answer
Write a program that simulates a dice roll by picking a random number from 1-6 and then picking a second random number from 1-6. Add the two values together, and display the total.Sample Output :
46. One Shot Hi-Lo - Link
- Task
- Answer
Write a program that picks a random number from 1-100. Give the user a chance to guess it. If they get it right, tell them so. If their guess is higher than the number, say “Too high.” If their guess is lower than the number, say “Too low.” Then quit. (They don’t get any more guesses for now.)Sample Output :
47. Three Card Monte - Link
- Task
- Answer
Write a program that allows the user to play a simple game of Three Card Monte. Create three cards. One of the cards is the Queen. The others are Jokers. Shuffle the cards, then ask the player to pick a card. After the player picks a card, shuffle the cards again and show the player that the Queen is not where they picked. If the player picks the Queen, they win. If they don’t pick the Queen, they lose.Sample Output :(Note that this is basically just a number-guessing game with fancy graphics.)
75. Baby Blackjack - Link
- Task
- Answer
Write a program that allows a human user to play a single hand of “blackjack” against a dealer.
- Pick two values from 1-10 for the player. These are the player’s “cards”.
- Pick two more values from 1-10 for the dealer.
- Whoever has the highest total is the winner.
- There is no betting, no busting, and no hitting. Save that for real blackjack.