SlideShare a Scribd company logo
1 of 5
Download to read offline
/************************************************************************************
****************************
* Amy Baxter
* Jave program
*
*
* The program is designed to run a roullette game in which the user can place bets
and gain or lose money.
*************************************************************************************
**************************/
import java.util.Random;
import java.util.Scanner;
public class roullette {
public static void main(String[] args)
{
//delcare variables
int choice;
int bet;
boolean win;
int cash = 100;
boolean flag = false;
displayWelcome();
Scanner stdIn = new Scanner(System.in);
while (flag == false) {
choice = getMenuChoice(stdIn);
bet = getBet(stdIn, cash);
if (choice == 1) {
win = playNumberBet(stdIn);
if (win == true) {
cash = cash + bet * 35;
System.out.println("COngratulations! You won, you
have $"
+ cash);
}
else {
cash = cash - bet;
System.out
.println("Sorry! You lose! You now have
$" + cash);
}
}
// end if
// begin color bet
if (choice == 2) {
win = playColorBet(stdIn);
if (win == true) {
cash = cash + bet * 1;
System.out.println("COngratulations! You won, you
have $"
+ cash);
}
else {
cash = cash - bet;
System.out
.println("Sorry! You lose! You now have
$" + cash);
}
}
// end if #2
if (choice == 3) {
flag = true;
System.out.println("Cash Out!!! You leave with $" + cash);
}
if (cash <= 0) {
flag = true;
System.out.println("You're super duper broke!");
}
}
System.out.println("Thanks for Playing!");
}
// end main
public static void displayWelcome() {
System.out.println("############################n"
+ "# WELCOME TO ROULETTE #n"
+ "############################n"
+ "# NUMBER BETS PAYOUT: 35:1 #n"
+ "# COLOR BETS PAYOUT: 1:1 #n"
+ "############################");
}
public static int getMenuChoice(Scanner stdIn) {
System.out.println("---Choose a Bet---n" + "1. pick a numbern"
+ "2. pick a colourn" + "3. cash out.n");
boolean flag = false;
int input = 0;
while (flag == false) {
System.out.println("Enter a choice (1-3):");
input = stdIn.nextInt();
if (input == 1 || input == 2 || input == 3) {
flag = true;
}
}
return input;
}
// end method
public static int getBet(Scanner stdIn, int cash) {
boolean flag = false;
int input = 0;
while (flag == false) {
System.out.println("Enter your bet ( 1-" + cash + "):");
input = stdIn.nextInt();
if (input > 0 && input <= cash) {
flag = true;
}
}
return input;
}
// end method
public static int spin() {
Random generator = new Random();
int roll = generator.nextInt(37);
return roll;
}
// end method
public static boolean playNumberBet(Scanner stdIn) {
int spin = spin();
int input = 0;
boolean flag = false;
while (flag == false) {
System.out.println("Enter a number (0-36): ");
input = stdIn.nextInt();
if (input >= 0 && input <= 36) {
flag = true;
}
}
// end while loop
String color = determinColor(spin);
if (input == spin) {
System.out.println("Congrats you won! you rolled a " + color + "
"
+ spin);
return true;
}
else {
System.out.println("Sorry you lost! You spun a " + color + " "
+ spin);
return false;
}
}// end method
public static boolean playColorBet(Scanner stdIn) {
int spin = spin();
String input;
boolean flag = false;
do {
System.out.println("Enter a color (red or black): ");
input = stdIn.next();
input = input.toLowerCase();
if (input.equals("red") || input.equals("black")) {
flag = true;
}
} while (flag == false);// end while loop
String color = determinColor(spin);
if (color.equals(input)) {
System.out.println("Congrats you won! you rolled a " + color + "
"
+ spin);
return true;
}
else {
System.out.println("Sorry you lost! You spun a " + color + " "
+ spin);
return false;
}
}
// end method
public static String determinColor(int color) {
if (color % 2 == 0) {
return "red";
}
else {
return "black";
}
}
}

More Related Content

Viewers also liked

Practical example of how digital resources link with learning intentions
Practical example of how digital resources link with learning intentionsPractical example of how digital resources link with learning intentions
Practical example of how digital resources link with learning intentionsanaair15
 
Fast Quick and Strong Vashikaran Totke and Upay
Fast Quick and Strong Vashikaran Totke and UpayFast Quick and Strong Vashikaran Totke and Upay
Fast Quick and Strong Vashikaran Totke and UpayLove Mantra Vashikaran
 
HumanPoweredEnergyDevice
HumanPoweredEnergyDeviceHumanPoweredEnergyDevice
HumanPoweredEnergyDeviceAmy Baxter
 
Nurse Course: Pathologies cervicales en neurochirurgie 3/4
Nurse Course: Pathologies cervicales en neurochirurgie 3/4Nurse Course: Pathologies cervicales en neurochirurgie 3/4
Nurse Course: Pathologies cervicales en neurochirurgie 3/4Michel Triffaux
 
Nurse Course Pathologies thoraco lombaires en neurochirurgie 2/4
Nurse Course Pathologies thoraco lombaires en neurochirurgie 2/4Nurse Course Pathologies thoraco lombaires en neurochirurgie 2/4
Nurse Course Pathologies thoraco lombaires en neurochirurgie 2/4Michel Triffaux
 
Nurse Course CHwapi 1/4 Formation en neurochirurgie
Nurse Course CHwapi 1/4 Formation en neurochirurgieNurse Course CHwapi 1/4 Formation en neurochirurgie
Nurse Course CHwapi 1/4 Formation en neurochirurgieMichel Triffaux
 
Pathologies intracrâniennes: Formation pour le nursing d'étage en neurochiru...
Pathologies intracrâniennes:  Formation pour le nursing d'étage en neurochiru...Pathologies intracrâniennes:  Formation pour le nursing d'étage en neurochiru...
Pathologies intracrâniennes: Formation pour le nursing d'étage en neurochiru...Michel Triffaux
 

Viewers also liked (11)

Nota kkqt1
Nota kkqt1Nota kkqt1
Nota kkqt1
 
Prp_Portfolio
Prp_PortfolioPrp_Portfolio
Prp_Portfolio
 
Practical example of how digital resources link with learning intentions
Practical example of how digital resources link with learning intentionsPractical example of how digital resources link with learning intentions
Practical example of how digital resources link with learning intentions
 
Fast Quick and Strong Vashikaran Totke and Upay
Fast Quick and Strong Vashikaran Totke and UpayFast Quick and Strong Vashikaran Totke and Upay
Fast Quick and Strong Vashikaran Totke and Upay
 
HumanPoweredEnergyDevice
HumanPoweredEnergyDeviceHumanPoweredEnergyDevice
HumanPoweredEnergyDevice
 
Giftmaker Product Profile,Mubai
Giftmaker Product Profile,MubaiGiftmaker Product Profile,Mubai
Giftmaker Product Profile,Mubai
 
Nurse Course: Pathologies cervicales en neurochirurgie 3/4
Nurse Course: Pathologies cervicales en neurochirurgie 3/4Nurse Course: Pathologies cervicales en neurochirurgie 3/4
Nurse Course: Pathologies cervicales en neurochirurgie 3/4
 
Economic report-2014-2015
Economic report-2014-2015Economic report-2014-2015
Economic report-2014-2015
 
Nurse Course Pathologies thoraco lombaires en neurochirurgie 2/4
Nurse Course Pathologies thoraco lombaires en neurochirurgie 2/4Nurse Course Pathologies thoraco lombaires en neurochirurgie 2/4
Nurse Course Pathologies thoraco lombaires en neurochirurgie 2/4
 
Nurse Course CHwapi 1/4 Formation en neurochirurgie
Nurse Course CHwapi 1/4 Formation en neurochirurgieNurse Course CHwapi 1/4 Formation en neurochirurgie
Nurse Course CHwapi 1/4 Formation en neurochirurgie
 
Pathologies intracrâniennes: Formation pour le nursing d'étage en neurochiru...
Pathologies intracrâniennes:  Formation pour le nursing d'étage en neurochiru...Pathologies intracrâniennes:  Formation pour le nursing d'étage en neurochiru...
Pathologies intracrâniennes: Formation pour le nursing d'étage en neurochiru...
 

Similar to RussianRouletteProgram

java-introduction.pdf
java-introduction.pdfjava-introduction.pdf
java-introduction.pdfDngTin307322
 
public interface Game Note interface in place of class { .pdf
public interface Game  Note interface in place of class { .pdfpublic interface Game  Note interface in place of class { .pdf
public interface Game Note interface in place of class { .pdfkavithaarp
 
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014Supriya Radhakrishna
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfarchanaemporium
 
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdfoperating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdfarasanmobiles
 
Program(Output)
Program(Output)Program(Output)
Program(Output)princy75
 
This is my code- #include -llvm-IR-LegacyPassManager-h- #include -llv.pdf
This is my code-  #include -llvm-IR-LegacyPassManager-h- #include -llv.pdfThis is my code-  #include -llvm-IR-LegacyPassManager-h- #include -llv.pdf
This is my code- #include -llvm-IR-LegacyPassManager-h- #include -llv.pdfEricvtJFraserr
 
Investor2017 show final_v3_rainvestors_compressed
Investor2017 show final_v3_rainvestors_compressedInvestor2017 show final_v3_rainvestors_compressed
Investor2017 show final_v3_rainvestors_compressedRockwellAutomationIR
 
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdfHere is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdftrishulinoverseas1
 

Similar to RussianRouletteProgram (20)

Java
JavaJava
Java
 
java-introduction.pdf
java-introduction.pdfjava-introduction.pdf
java-introduction.pdf
 
RandomGuessingGame
RandomGuessingGameRandomGuessingGame
RandomGuessingGame
 
COnnect4Game
COnnect4GameCOnnect4Game
COnnect4Game
 
Pro.docx
Pro.docxPro.docx
Pro.docx
 
Quick reference for sqoop
Quick reference for sqoopQuick reference for sqoop
Quick reference for sqoop
 
002207866
002207866002207866
002207866
 
public interface Game Note interface in place of class { .pdf
public interface Game  Note interface in place of class { .pdfpublic interface Game  Note interface in place of class { .pdf
public interface Game Note interface in place of class { .pdf
 
Quiz using C++
Quiz using C++Quiz using C++
Quiz using C++
 
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
 
Readme
ReadmeReadme
Readme
 
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdfoperating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
 
Ph 37
Ph 37Ph 37
Ph 37
 
Ph 38
Ph 38Ph 38
Ph 38
 
Program(Output)
Program(Output)Program(Output)
Program(Output)
 
This is my code- #include -llvm-IR-LegacyPassManager-h- #include -llv.pdf
This is my code-  #include -llvm-IR-LegacyPassManager-h- #include -llv.pdfThis is my code-  #include -llvm-IR-LegacyPassManager-h- #include -llv.pdf
This is my code- #include -llvm-IR-LegacyPassManager-h- #include -llv.pdf
 
Ph 3
Ph 3Ph 3
Ph 3
 
Investor2017 show final_v3_rainvestors_compressed
Investor2017 show final_v3_rainvestors_compressedInvestor2017 show final_v3_rainvestors_compressed
Investor2017 show final_v3_rainvestors_compressed
 
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdfHere is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
 

RussianRouletteProgram

  • 1. /************************************************************************************ **************************** * Amy Baxter * Jave program * * * The program is designed to run a roullette game in which the user can place bets and gain or lose money. ************************************************************************************* **************************/ import java.util.Random; import java.util.Scanner; public class roullette { public static void main(String[] args) { //delcare variables int choice; int bet; boolean win; int cash = 100; boolean flag = false; displayWelcome(); Scanner stdIn = new Scanner(System.in); while (flag == false) { choice = getMenuChoice(stdIn); bet = getBet(stdIn, cash); if (choice == 1) { win = playNumberBet(stdIn); if (win == true) { cash = cash + bet * 35; System.out.println("COngratulations! You won, you have $" + cash); } else { cash = cash - bet; System.out .println("Sorry! You lose! You now have $" + cash); } } // end if // begin color bet
  • 2. if (choice == 2) { win = playColorBet(stdIn); if (win == true) { cash = cash + bet * 1; System.out.println("COngratulations! You won, you have $" + cash); } else { cash = cash - bet; System.out .println("Sorry! You lose! You now have $" + cash); } } // end if #2 if (choice == 3) { flag = true; System.out.println("Cash Out!!! You leave with $" + cash); } if (cash <= 0) { flag = true; System.out.println("You're super duper broke!"); } } System.out.println("Thanks for Playing!"); } // end main public static void displayWelcome() { System.out.println("############################n" + "# WELCOME TO ROULETTE #n" + "############################n" + "# NUMBER BETS PAYOUT: 35:1 #n" + "# COLOR BETS PAYOUT: 1:1 #n" + "############################"); } public static int getMenuChoice(Scanner stdIn) { System.out.println("---Choose a Bet---n" + "1. pick a numbern" + "2. pick a colourn" + "3. cash out.n"); boolean flag = false; int input = 0; while (flag == false) { System.out.println("Enter a choice (1-3):"); input = stdIn.nextInt();
  • 3. if (input == 1 || input == 2 || input == 3) { flag = true; } } return input; } // end method public static int getBet(Scanner stdIn, int cash) { boolean flag = false; int input = 0; while (flag == false) { System.out.println("Enter your bet ( 1-" + cash + "):"); input = stdIn.nextInt(); if (input > 0 && input <= cash) { flag = true; } } return input; } // end method public static int spin() { Random generator = new Random(); int roll = generator.nextInt(37); return roll; } // end method public static boolean playNumberBet(Scanner stdIn) { int spin = spin(); int input = 0; boolean flag = false; while (flag == false) { System.out.println("Enter a number (0-36): "); input = stdIn.nextInt(); if (input >= 0 && input <= 36) { flag = true; } } // end while loop String color = determinColor(spin); if (input == spin) { System.out.println("Congrats you won! you rolled a " + color + " " + spin);
  • 4. return true; } else { System.out.println("Sorry you lost! You spun a " + color + " " + spin); return false; } }// end method public static boolean playColorBet(Scanner stdIn) { int spin = spin(); String input; boolean flag = false; do { System.out.println("Enter a color (red or black): "); input = stdIn.next(); input = input.toLowerCase(); if (input.equals("red") || input.equals("black")) { flag = true; } } while (flag == false);// end while loop String color = determinColor(spin); if (color.equals(input)) { System.out.println("Congrats you won! you rolled a " + color + " " + spin); return true; } else { System.out.println("Sorry you lost! You spun a " + color + " " + spin); return false; } } // end method public static String determinColor(int color) { if (color % 2 == 0) { return "red"; } else {