1st.
if the user inputs no when asked if they want to play again my game is suppose to go through a series of if statements depending the users outcome. My problem is that if i input "no" the game displays the correct message but once it is done displaying the message it starts the game over, i need it to end
2nd.
my game is suppose to stop once the number bet reaches zero and not allow the user to continue the bet if it is going to be below zero. however on mine if my bet continues regardless and if it is <= zero it repeats the game I want it to end.
(I am figuring it is a loop problem, but I am terrible with loops) PLEASE HELP!!
import javax.swing.JOptionPane; //importing the JOptionPane option
import java.util.Random; //importing random numbers for slot machine
import java.text.DecimalFormat; //importig decimal formatter option
public class PRACTICE_3 // Jay Masi, jmm72@pitt.edu, M W 3:00 - 4:15
{
public static void main (String [] args) //Main method
{
Random questions = new Random(); //Establishing the random question variable
DecimalFormat formatter = new DecimalFormat("#0.00"); //Allowing the pecentage to be confined
int sign1 = 0; //First number on machine
int sign2 = 0; //Second number on machine
int sign3 = 0; //Third number on machine
double number = 0.0; //Inital bet
double winnings = 0.0; //Total winnings
double balance = 0.0; //Variable for the updateBalance method
double bet = 0.0; //Variable
String input;
String ask;
input = JOptionPane.showInputDialog("Welcome to Jay's Slot Machine \n\nPlace your bet");
number = Double.parseDouble(input);
while(number%.25!=0)
{
input = JOptionPane.showInputDialog("Please Enter an amount divisible by $.25");
number = Double.parseDouble(input);
}
winnings = number;
input = JOptionPane.showInputDialog("your balance is: $"+formatter.format(winnings)+"\nHow much do you want to bet?");
bet = Double.parseDouble(input);
/* Declaring the while loop in order to play the slots */
while(bet >= .25 && bet <= number)
{
// Figuring out the random numbers for the slots
sign1 = (Math.abs(questions.nextInt())%6);
sign2 = (Math.abs(questions.nextInt())%6);
sign3 = (Math.abs(questions.nextInt())%6);
JOptionPane.showMessageDialog(null, sign1+" - "+sign2+" - "+sign3);
// Calling the method to receive the results
balance = updateBalance( sign1, sign2, sign3, bet);
// Keeping track of the total winnings
winnings += balance;
if(bet > winnings)
input = JOptionPane.showInputDialog("Your balance is $"+formatter.format(winnings)+"\nPlease enter another bet less than or equal to your balance that is divisible by $.25");
if(winnings > 0)
input = JOptionPane.showInputDialog("Your Balance is $"+formatter.format(winnings)+"\nDo you want to play again?", "yes or no");
if(input.equals("no"))
if(winnings > number)
JOptionPane.showMessageDialog(null, "Thank you for Playing \nYou Won $"+formatter.format(winnings-number));
if(winnings == number)
JOptionPane.showMessageDialog(null, "Thank you for Playing \nYou Broke Even");
if(winnings < number)
JOptionPane.showMessageDialog(null, "Thank you for Playing \nYou Lost $"+formatter.format(number-winnings)+" from your original bet of $"+formatter.format(number));
}
System.exit(0);
}
// The udateBalance method
public static double updateBalance(int s1, int s2, int s3, double B)
{
DecimalFormat formatter = new DecimalFormat("#0.00"); // Declaring the decimal format variable
double n = 0; // return variable
// Payout rules
if (s1 == s2 && s2 == s3)
{
if (s1 == 0){
n = (0 * B);
JOptionPane.showMessageDialog(null, "You Got All 0's \nYou Won $"+formatter.format(n));}
if (s1 == 1){
n = (1 * B);
JOptionPane.showMessageDialog(null, "You Got All 1's \nYou Won $"+formatter.format(n));}
if (s1 == 2){
n = (2 * B);
JOptionPane.showMessageDialog(null, "You Got All 2's \nYou Won $"+formatter.format(n));}
if (s1 == 3){
n = (3 * B);
JOptionPane.showMessageDialog(null, "You Got All 3's \nYou Won $"+formatter.format(n));}
if (s1 == 4){
n = (4 * B);
JOptionPane.showMessageDialog(null, "You Got All 4's \nYou Won $"+formatter.format(n));}
if (s1 == 5){
n = (400 * B);
JOptionPane.showMessageDialog(null, "JACKPOT!!!!! \nYou Won $"+formatter.format(n));}
}
else
{
if (s1 == s2 && s2 != s3 || s1 == s3 && s1 != s2 || s2 == s3 && s2 != s1)
{
n = b;
JOptionPane.showMessageDialog(null, "You Got 2 Of Them \nYou Recieved Back Your $"+formatter.format(n));
}
else
{
n = -b;
JOptionPane.showMessageDialog(null, "You Didn't Get Any Right You Lost $"+formatter.format(Math.abs(n)));
}
}
return n;
}

New Topic/Question
Reply




MultiQuote




|