Extra Credit Assignment 1: Rock – Paper – Scissors

Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When played between two people, each person picks one of three options (usually shown by a hand gesture) at the same time, and a winner is determined. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should randomly choose one of the three options (without revealing it) then prompt for the user’s selection. At that point, the program reveals both choices and indicates if the user won, the computer won, or if there was a tie. Continue playing until the user chooses to stop, and then show the number of user wins, losses, and ties.

Extra Credit Assignment 2: Slot Machine

Write an application that simulates a slot machine. The player starts out with M coins. The value of M is an input to the program, and you charge 25 cents per coin. For each play, the player can bet 1 to 4 coins. If the player enters 0 as the number of coins to bet, then the program stops playing. At the end of the game, the program displays the number of coins left and how much the player won or lost in the dollar amount. There are three slots on the machine, and each slot will display one of the three possible pieces: BELL, GRAPE, and CHERRY. When certain combinations appear on the slots, the machine will pay the player. The payoff combinations are these:

No. Combinations Payoff (times betting amount)
1 BELL BELL BELL 10
2 GRAPES GRAPES GRAPES 7
3 CHERRY CHERRY CHERRY 5
4 CHERRY CHERRY ----------- 3
5 CHERRY ---------- CHERRY 3
6 ---------- CHERRY CHERRY 3
7 CHERRY --------- ----------- 1
8 ---------- CHERRY --------- 1
9 --------- ---------- CHERRY 1

The symbol --------- means any piece. If the player bets 4 coins and gets combination 5, for example, the machine pays the player 12 coins.

Extra Credit Assignment 3: Loan Calculator

The monthly payments for a given loan are divided into amounts that apply to the principal and to the interest. For example, if you make a monthly payment of $500, only a portion of the $500 goes to the principal and the remainder is the interest payment. The monthly interest is computed by multiplying the monthly interest rate by the unpaid balance. The monthly payment minus the monthly interest is the amount applied to the principal. The following table is the sample loan payment schedule for a one-year loan of $5,000 with a 12 percent annual interest rate. The monthly payment would be $444.24.

Extra Credit Assignment 4: Dice-Throwing Simulator

Write a complete program that simulates the rolling of two dice. More specifically, it simulates a user-specified number of rolls and then prints a histogram of the number of rolls for each possible pair value. In other words, it prints a histogram for the number of times that two was thrown, the number of times that three was thrown, and so on, all the way up to the number of times that twelve was thrown. Use a frequency array to keep track of the number of times each pair value is thrown. For example, the frequency[2] element holds the number of times two is thrown. The frequency[3] element holds the number of times three is thrown.

As part of your program, write a DiceSimulation class that implements these methods:

  • newSimulation ─ This method clears out the frequency array (assigns all elements to zero), prompts the user for the number of rolls, and then simulates the rolls.
  • additionalRolls ─ This method prompts the user for the number of rolls that should be added to the current dice-rolling simulation. It then simulates the additional rolls.
  • printReport ─ This method prints the dice-rolling simulation results.

As always, you should:

  • Limit your use of class variables and instance variables – only use them if appropriate.
  • Use appropriate modifiers for your methods. The modifiers we’ve discussed are private, public, static, and final.
  • Use helper methods if appropriate.

A sample run of the program is shown below. (Note: Bold texts are user input.)

Welcome to the dice throwing simulator!
Options: (n)ew simulation, (a)dditional rolls, (p)rint, (q)uit
Enter n, a, p, or q ==> x
Invalid selection.
Options: (n)ew simulation, (a)dditional rolls, (p)rint, (q)uit
Enter n, a, p, or q ==> N
How many dice rolls would you like to simulate? 200
Options: (n)ew simulation, (a)dditional rolls, (p)rint, (q)uit
Enter n, a, p, or q ==> a
How many additional rolls? 100
Options: (n)ew simulation, (a)dditional rolls, (p)rint, (q)uit
Enter n, a, p, or q ==> p
DICE ROLLING SIMULATION RESULTS
Each "*" represents 1% of the total number of rolls.
Total number of rolls = 300.
2: ***
3: *******
4: ********
5: ***********
6: *************
7: *******************
8: ***************
9: ********
10: **********
11: *****
12: *
Options: (n)ew simulation, (a)dditional rolls, (p)rint, (q)uit
Enter n, a, p, or q ==> a
How many additional rolls? 10000
Options: (n)ew simulation, (a)dditional rolls, (p)rint, (q)uit
Enter n, a, p, or q ==> p
DICE ROLLING SIMULATION RESULTS
Each "*" represents 1% of the total number of rolls.
Total number of rolls = 10300.
2: ***
3: *****
4: ********
5: ***********
6: **************
7: *****************
8: **************
9: ***********
10: *********
11: ******
12: **
Options: (n)ew simulation, (a)dditional rolls, (p)rint, (q)uit
Enter n, a, p, or q ==> n
How many dice rolls would you like to simulate? 100
Options: (n)ew simulation, (a)dditional rolls, (p)rint, (q)uit
Enter n, a, p, or q ==> p
DICE ROLLING SIMULATION RESULTS
Each "*" represents 1% of the total number of rolls.
Total number of rolls = 100.
2: ***
3: ***
4: ***********
5: ***********
6: ********
7: ******************
8: ****************
9: **********
10: *************
11: *****
12: **
Options: (n)ew simulation, (a)dditional rolls, (p)rint, (q)uit
Enter n, a, p, or q ==> q
Thank you, good bye!
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.