Question

Hey, i'm super stuck on my lab in cs102. I have attempted it but never got...

Hey, i'm super stuck on my lab in cs102. I have attempted it but never got close to what the end result should be. Please help, due in 2 days!!

Assignment

You will be writing a program to simulate a slot machine. The player will start with $1000 and you will repeatedly ask the user how much money they wish to insert into the machine before spinning, or allow the player to quit. If the player runs out of money, the game is over. Additionally, the player cannot spend more money than they have available. You should store the player's wagers and winnings in order to output statistics when the user is done playing.

Spinning and Payouts

After placing a bet, the money is immediately subtracted from the player's balance. The slot machine has 3 reels which are spun after the lever is pulled. Each reel will randomly contain a integer value between 2 and 7 inclusive after being spun. If the all 3 reels have the value 7, the player obtained a jackpot and will receive the amount which they wagered times 10. If all 3 reels match, but contain a value other than 7, award the player their wagered amount times 5. Otherwise, if only 2 reels match, award the player their wager times 2. If none of the reels match, the player does not receive any earnings.

Restrictions / Hints

1. At the start, ask the user for a seed to use for the random number generator. Use this value to seed your random numbers.

2. Before each spin, show the user their current balance and ask for a wager.

3. The slot machine only accepts wagers containing whole dollar amounts. You may not enter any spare change.

4. You must use an array to store the value of each reel.

5. You must use a for loop to input the random values of each reel.

6. You must use a vector to store the amount of each wager.

7. You must use a vector to store the winnings of each spin.

8. If the user wagers an amount of 0 or less, stop playing and output play statistics. Additionally, if the user has a balance of $0 and is unable to wager, end the game and output play statistics. If the user never played and walks away immediately, do not output any statistics.

9. At the end, output a summary of each spin including the wager and amount won. Then output the smallest and largest wager, and the smallest non-zero winnings and the largest winnings from a single spin. Note that if the user never wins, the smallest and largest winnings displayed should be 0.

I know its alot of stuff and restrictions but I'd really appreicate it if someone can write a correct code so I can figure out where i went wrong. TYY

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import acm.program.*;
import acm.util.*;

/*
* THIS PROGRAM SIMULATES THE SLOT MACHINE
*/

public class cap6ex5 extends ConsoleProgram{

private RandomGenerator rgen = RandomGenerator.getInstance();

private int money = 50; //starting stake

private String value = "";

public void run(){


String instAnswer = readLine("Would you like instructions?");

while (!instAnswer.equals("yes") && !instAnswer.equals("no")) {
instAnswer = readLine("Answer yes or no.");
}
if (instAnswer.equals("yes")) println("YOU SHOUD KNOW!");


startGame(money);

}
private void startGame(int x){
String keepPlaying = "";
int finalMoney = x;
int prize = 0;
while (finalMoney > 0){
keepPlaying = readLine("You have $" + finalMoney +". Would you like to play?");
//avoid different answers
while(true){
if (keepPlaying.equals("yes") || keepPlaying.equals("no")) break;
keepPlaying = readLine("Asnwer yes or no.");

}
if (keepPlaying.equals("no")) break;

finalMoney--;
prize = gamePrize();
finalMoney += prize;
println(value + " -- You win $" + prize);
}

println("Okay, bye. You ended with $" + finalMoney);
}
private int gamePrize(){
int countBAR = 0; //BAR == 1
int countBELL = 0; //BELL == 2
int countPLUM = 0; //PLUM == 3
int countORANGE = 0;//ORANGE == 4
int countCHERRY = 0;//CHERRY == 5
value = "";


for (int i = 1; i <= 3 ; i++){
int x = rgen.nextInt(1, 6);

switch(x){
case 1:
countBAR++;
value += "BAR ";
break;
case 2:
countBELL++;
value += "BELL ";
break;
case 3:
countPLUM++;
value += "PLUM ";
break;
case 4:
countORANGE++;
value += "ORANGE ";
break;
case 5:
countCHERRY++;
value += "CHERRY ";
break;
case 6: value += "LEMON "; break;
}

}

return result(countBAR, countBELL, countPLUM, countORANGE, countCHERRY);

}
private int result(int bar, int bell, int plum, int orange, int cherry){
int prize = 0;
if (bar == 3){
prize = 250;
} else if ((bell > 1 && bar ==1) || bell == 3){
prize = 20;
} else if ((plum > 1 && bar == 1) || plum == 3){
prize = 14;
} else if ((orange >1 && bar == 1) || orange == 3){
prize = 10;
} else switch(cherry){
case 1: prize = 7; break;
case 2: prize = 5; break;
case 3: prize = 2; break;
}
return prize;
}

}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
Hey, i'm super stuck on my lab in cs102. I have attempted it but never got...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • Just do program 6 using c++ which are printf and scanf. Please don’t use cout and...

    Just do program 6 using c++ which are printf and scanf. Please don’t use cout and cin. Program 4: A slot machine has three windows. A random fruit is picked for each window from cherry apple, lemon, and orange. If all three windows match, the user wins 8 times the bet amount. If the first two windows only are cherries, the user wins 3 times the bet amount. If the first window is a cherry and the second window is...

  • You will write a two-class Java program that implements the Game of 21. This is a...

    You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...

  • Problem Statement: A company intends to offer various versions of roulette game and it wants you...

    Problem Statement: A company intends to offer various versions of roulette game and it wants you to develop a customized object-oriented software solution. This company plans to offer one version 100A now (similar to the simple version in project 2 so refer to it for basic requirements, but it allows multiple players and multiple games) and it is planning to add several more versions in the future. Each game has a minimum and maximum bet and it shall be able...

  • HEy GUYS PLZ I WROTE THIS CODE BUT I WAS ASKED TO ADD SOME ASSERTION TESTS AND I HAVE NEVER DONE SUCH THING. CAN YOU GUY...

    HEy GUYS PLZ I WROTE THIS CODE BUT I WAS ASKED TO ADD SOME ASSERTION TESTS AND I HAVE NEVER DONE SUCH THING. CAN YOU GUYS HELPS ME OUT ON HOW TO TEST A SIMPLE CODE SINCE ITS A GUESSING GAME! THANK YOU. PYTHON import random # here it allows us to use the benefits of the functions random #function 1 which is just a screen organized wordings def screen): screeninstructions () name input("Your Name : ") print('Welcome, name, 'This...

  • I'm having trouble understanding pointers in my c programming class. I posted the pointer assignment below....

    I'm having trouble understanding pointers in my c programming class. I posted the pointer assignment below. If you could leave comments pointing out where pointers are used it would be much appreciated! ----------------------------------------------------------------------------------------------------------------------------------- Write a complete C program for an automatic teller machine that dispenses money. The user should enter the amount desired (a multiple of 10 dollars) and the machine dispenses this amount using the least number of bills. The bills dispenses are 50s, 20s, and 10s. Write a...

  • In java language here is my code so far! i only need help with the extra...

    In java language here is my code so far! i only need help with the extra credit part For this project, you will create a Rock, Paper, Scissors game. Write a GUI program that allows a user to play Rock, Paper, Scissors against the computer. If you’re not familiar with Rock, Paper, Scissors, check out the Wikipedia page: http://en.wikipedia.org/wiki/Rock-paper-scissors This is how the program works: The user clicks a button to make their move (rock, paper, or scissors). The program...

  • This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named...

    This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named Budgeter.java. To use a Scanner for console input, you must import java.util.*; in your code. This program prompts a person for income and expense amounts, then calculates their net monthly income. Below are two example logs of execution from the program. This program’s behavior is dependent on the user input (user input is bold and underlined below to make it stand out and differentiate...

  • I need help in C++ . Project 3 – Parking Deck Ticketing System Objectives: Use if,...

    I need help in C++ . Project 3 – Parking Deck Ticketing System Objectives: Use if, switch, and loop statements to solve a problem. Use input and output statements to model a real world application Incorporate functions to divide the program into smaller segments Instructions: Your task is to write a program that simulates a parking meter within the parking deck. The program will start by reading in the time a car arrives in the parking deck. It will then...

  • For this project, you are tasked with creating a text-based, basic String processing program that performs...

    For this project, you are tasked with creating a text-based, basic String processing program that performs basic search on a block of text inputted into your program from an external .txt file. After greeting your end user for a program description, your program should prompt the end user to enter a .txt input filename from which to read the block of text to analyze. Then, prompt the end user for a search String. Next, prompt the end user for the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT