Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ChuckALuck {
- public static void main (String[] args) {
- Scanner s = new Scanner(System.in);
- double bankRoll = bankRoll(s);
- int i = 1;
- while(i==1) {
- bankRoll = gamePlay(s, bankRoll);
- i = gameEnd(i, bankRoll, s);
- }
- }
- public static double bankRoll(Scanner s) {
- System.out.println("How much do you want to add to your bankroll?");
- System.out.println("(Please use a decimal value)");
- double bankRoll = s.nextDouble();
- return bankRoll;
- }
- public static double gamePlay(Scanner s, double br) {
- int i = 0;
- while(i==0) {
- System.out.println("What is the value of your next bet ($0.00 - $" + br + ")?");
- double betValue = s.nextDouble();
- br = br - betValue;
- // ensures a correct bet value is chosen
- if (betValue <= br) {
- i = 1;
- }
- else {
- System.out.println("You cannot bet more than what is in your bankroll. Try again.");
- }
- }
- // Takes the bet number
- while(i==1) {
- System.out.println("Choose a number between 1 and 6:");
- int betNumber = s.nextInt();
- // ensures a correct dice value is chosen
- if ((1<=betNumber)&&(betNumber<=6)) {
- i = 0;
- }
- else {
- System.out.println("That is not a valid selection. Try again.");
- }
- }
- //dice rolls
- Random r = new Random();
- int rollOne = r.nextInt(6) + 1;
- int rollTwo = r.nextInt(6) + 1;
- int rollThree = r.nextInt(6) + 1;
- System.out.println("Dice rolls: "+rollOne+" "+rollTwo+" "+rollThree);
- // calculates and prints winnings
- int matchingDie = 0;
- if(betNumber == rollOne) {
- matchingDie++;
- }
- if(betNumber == rollTwo) {
- matchingDie++;
- }
- if(betNumber == rollThree) {
- matchingDie++;
- }
- if(matchingDie==1) {
- double winnings = betValue;
- System.out.println("Winnings = $"+ winnings);
- return br + winnings;
- }
- if(matchingDie==2) {
- double winnings = betValuex2;
- System.out.println("Winnings = $"+ winnings);
- return br + winnings;
- }
- if(matchingDie==3) {
- double winnings = betValuex10;
- System.out.println("Winnings = $"+ winnings);
- return br + winnings;
- }
- if(matchingDie==0) {
- double winnings = 0.00;
- System.out.println("Winnings = $"+ winnings);
- return br;
- }
- }
- public static int gameEnd(int gameNum, double br, Scanner s) {
- System.out.println("After bet "+gameNum+" your bankroll is $"+br);
- System.out.println();
- System.out.println("Do you want to keep playing?");
- String replay = s.nextString();
- if(replay=="y"){
- return 1;
- }
- if(replay=="yes"){
- return 1;
- }
- if(replay=="n"){
- return 0;
- }
- if(replay=="no"){
- return 0;
- }
- }
- }
Add Comment
Please, Sign In to add comment