My problem here is that I am trying to get the getBigJackpot() to correctly woork. If I were to win say 10 coins, it would store in an int, but if I were to win 5 coins, that 10 would stay and disregard the 5 coins won. If I were to win 15 coins, it would replace the 10. I don't know which way to go with this.

Line 153 is where this starts.

import java.util.*;

public class SlotMachine
{
   // Set constants
   final int QUIT = 4;
   final int INIBET = 0;
   final int Z = 0;
   final int SLOT = 2;
   final int RMAX = 6;
   final int MAX = 2;
 
   // Declare variables
   int bigJack = 0;
   int ChooseSlot;
   int setSlot;
   int choice;
   int Slot1;
   int Slot2;
   int bet = 0;
   int bigBet = 0;
 
   // Invoke the Scanner
   Scanner scan = new Scanner(System.in);
 
   // Constructor
   public SlotMachine()
   {
      // Constructor for a slot machine with
      // an initial bet of 0
      bet = INIBET;
   }// End of SlotMachine()
 
   public void play()
   {
	   System.out.println("in play");
	   // Do this until the user quits
      boolean done = false;
      while (!done)
      {
         System.out.println(this.ChooseSlot);
         //choice = ChooseSlot;
         if(this.ChooseSlot == SLOT)
             System.out.println("The current state of Slot Machine Two: " + bet);
         else
            System.out.println("The current state of Slot Machine One: " + bet);
     
         // print-out the menu
         System.out.println();
         System.out.println("******** MENU ********");
         System.out.println("* 1. Rest Bet To 0.  *");
         System.out.println("* 2. Bet One Coin.   *");
         System.out.println("* 3. Pull the handle.*");
         System.out.println("* 4. Walk Away       *");
         System.out.println("**********************");
         System.out.println("* Enter choice(1-4): *");
         System.out.println("**********************");
       
         // get the choice
         choice = scan.nextInt();
         System.out.println("You chose: " + choice);
         switch (choice)
         {
            case 1: 
               reset();
               break;
            case 2: 
               betOneCoin();
               System.out.println("Bet is: " + bet);
               break;  
            case 3:
               if(bet > Z)
                  pullTheHandle();
               else
                  System.out.println("You must bet at least one coin to pull the handle.");
               break;   
            case 4: 
               System.out.println("The current bet is: " + bet); // Walk Away option
               done = true;
               break;
            default:
               System.out.println("Invalid choice, try again.");
               break;
         } // switch
      }// End of while loop
   }// End of play()
 
   public int reset()
   {
      // Set the size of the current bet to 0 coins
      bet = INIBET;
      System.out.println("The current bet is reset to: " + bet);
      return bet;
   }
 
   public int betOneCoin()
   {
      for(int i = 0; i <= 3; i++)
      {
         if(bet > MAX)
         {
            System.out.println("You can not bet more than three coins.");
            bet = MAX;
         }
      }
      bet++;
      return bet;
    }
 
    public void pullTheHandle()
    {
       int numSlot1, numSlot2, numSlot3;
       Random generator = new Random();
  
       numSlot1 = generator.nextInt(RMAX);
       numSlot2 = generator.nextInt(RMAX);
       numSlot3 = generator.nextInt(RMAX);
  
       System.out.println(" | " + numSlot1 + " | " + numSlot2 + " | " + numSlot3 + " | ");
  
       // process the results
       if((numSlot1 == Z) && (numSlot2 == Z) && (numSlot3 == Z))
       {
          bet *= 10;
          if(bet < bigBet)
          getBigJackpot();
          System.out.println("You have won: " + bet + " coins");
          bet = Z;
       }
       else if((numSlot1 == numSlot2) && (numSlot1  == numSlot3) && (numSlot2 == numSlot3))
       {
          bet *= 5;
          if(bet < bigBet)
          getBigJackpot();
          System.out.println("You have won: " + bet + " coins");
          bet = Z;
       }
       else if((numSlot1 == numSlot2) || (numSlot1 == numSlot3) || (numSlot2 == numSlot3))
       {
          bet *= 2;
          if(bet < bigBet)
          getBigJackpot();
          System.out.println("You have won: " + bet + " coins");
          bet = Z;
       }
       else
       {
          bet -= bet;
          System.out.println("You loose. The bet is: " + bet);
       }
    }// End of pullHandle()
  
    public static int getBigJackpot()
    {
       // Returns the amount (in coins) of the biggest
       // jackpot won on any slot machine
       int i = 0; return i;
       //return SlotMachine.bigBet;
       //System.out.println("The Big Jackpot is: " + SlotMachine.bigBet);
    }// End of get BigJackpot()
 
    // Getters
    public int getBigBet() 
	 {
	    return bigBet;
	 }
    
	 public int getChooseSlot()
    {
       System.out.println(ChooseSlot);
       return ChooseSlot;
    }
 
    // Setters
    public void setBigBet() 
	 {
	    bigBet = bet;
	 }
    
	 public void setChooseSlot(int setSlot)
	 {
	    ChooseSlot = setSlot;
	 }
 
    public String toString()
    {
    // Returns a string that represents the current
    // state of this slot machine
       return  bet + " ";
    }
}

Rule of college: For every 1 hour in Java Programming class, 40 hours is required outside of Java Programming class smashing your fist into your face.

int i = 0; return i;

this will always return 0, and you are not actually setting a value that is used outside of that get method. a getter also isn't the right way to set values. what exactly is it that you are trying to do? which value should be changed? when? into what value?

My problem here is that I am trying to get the getBigJackpot() to correctly woork. If I were to win say 10 coins, it would store in an int, but if I were to win 5 coins, that 10 would stay and disregard the 5 coins won. If I were to win 15 coins, it would replace the 10. I don't know which way to go with this.

Line 153 is where this starts.

import java.util.*;

public class SlotMachine
{
   // Set constants
   final int QUIT = 4;
   final int INIBET = 0;
   final int Z = 0;
   final int SLOT = 2;
   final int RMAX = 6;
   final int MAX = 2;
 
   // Declare variables
   int bigJack = 0;
   int ChooseSlot;
   int setSlot;
   int choice;
   int Slot1;
   int Slot2;
   int bet = 0;
   int bigBet = 0;
 
   // Invoke the Scanner
   Scanner scan = new Scanner(System.in);
 
   // Constructor
   public SlotMachine()
   {
      // Constructor for a slot machine with
      // an initial bet of 0
      bet = INIBET;
   }// End of SlotMachine()
 
   public void play()
   {
	   System.out.println("in play");
	   // Do this until the user quits
      boolean done = false;
      while (!done)
      {
         System.out.println(this.ChooseSlot);
         //choice = ChooseSlot;
         if(this.ChooseSlot == SLOT)
             System.out.println("The current state of Slot Machine Two: " + bet);
         else
            System.out.println("The current state of Slot Machine One: " + bet);
     
         // print-out the menu
         System.out.println();
         System.out.println("******** MENU ********");
         System.out.println("* 1. Rest Bet To 0.  *");
         System.out.println("* 2. Bet One Coin.   *");
         System.out.println("* 3. Pull the handle.*");
         System.out.println("* 4. Walk Away       *");
         System.out.println("**********************");
         System.out.println("* Enter choice(1-4): *");
         System.out.println("**********************");
       
         // get the choice
         choice = scan.nextInt();
         System.out.println("You chose: " + choice);
         switch (choice)
         {
            case 1: 
               reset();
               break;
            case 2: 
               betOneCoin();
               System.out.println("Bet is: " + bet);
               break;  
            case 3:
               if(bet > Z)
                  pullTheHandle();
               else
                  System.out.println("You must bet at least one coin to pull the handle.");
               break;   
            case 4: 
               System.out.println("The current bet is: " + bet); // Walk Away option
               done = true;
               break;
            default:
               System.out.println("Invalid choice, try again.");
               break;
         } // switch
      }// End of while loop
   }// End of play()
 
   public int reset()
   {
      // Set the size of the current bet to 0 coins
      bet = INIBET;
      System.out.println("The current bet is reset to: " + bet);
      return bet;
   }
 
   public int betOneCoin()
   {
      for(int i = 0; i <= 3; i++)
      {
         if(bet > MAX)
         {
            System.out.println("You can not bet more than three coins.");
            bet = MAX;
         }
      }
      bet++;
      return bet;
    }
 
    public void pullTheHandle()
    {
       int numSlot1, numSlot2, numSlot3;
       Random generator = new Random();
  
       numSlot1 = generator.nextInt(RMAX);
       numSlot2 = generator.nextInt(RMAX);
       numSlot3 = generator.nextInt(RMAX);
  
       System.out.println(" | " + numSlot1 + " | " + numSlot2 + " | " + numSlot3 + " | ");
  
       // process the results
       if((numSlot1 == Z) && (numSlot2 == Z) && (numSlot3 == Z))
       {
          bet *= 10;
          if(bet < bigBet)
          getBigJackpot();
          System.out.println("You have won: " + bet + " coins");
          bet = Z;
       }
       else if((numSlot1 == numSlot2) && (numSlot1  == numSlot3) && (numSlot2 == numSlot3))
       {
          bet *= 5;
          if(bet < bigBet)
          getBigJackpot();
          System.out.println("You have won: " + bet + " coins");
          bet = Z;
       }
       else if((numSlot1 == numSlot2) || (numSlot1 == numSlot3) || (numSlot2 == numSlot3))
       {
          bet *= 2;
          if(bet < bigBet)
          getBigJackpot();
          System.out.println("You have won: " + bet + " coins");
          bet = Z;
       }
       else
       {
          bet -= bet;
          System.out.println("You loose. The bet is: " + bet);
       }
    }// End of pullHandle()
  
    public static int getBigJackpot()
    {
       // Returns the amount (in coins) of the biggest
       // jackpot won on any slot machine
       int i = 0; return i;
       //return SlotMachine.bigBet;
       //System.out.println("The Big Jackpot is: " + SlotMachine.bigBet);
    }// End of get BigJackpot()
 
    // Getters
    public int getBigBet() 
	 {
	    return bigBet;
	 }
    
	 public int getChooseSlot()
    {
       System.out.println(ChooseSlot);
       return ChooseSlot;
    }
 
    // Setters
    public void setBigBet() 
	 {
	    bigBet = bet;
	 }
    
	 public void setChooseSlot(int setSlot)
	 {
	    ChooseSlot = setSlot;
	 }
 
    public String toString()
    {
    // Returns a string that represents the current
    // state of this slot machine
       return  bet + " ";
    }
}

Rule of college: For every 1 hour in Java Programming class, 40 hours is required outside of Java Programming class smashing your fist into your face.

well i guess you'd have a global variable say coins... And the method would consist of if else statements that compare the new amount of coins against the old amount. The new amount of coins could be passed to the method via arguments and your total highest coins won so far would be stored in the global variable. your if statment might go like:

private static coins=0;
..
method(double newAmountWon) {
if(coins<newAmountWon) {//the new amount won was greater
coins=newAmountWon;//set the global total of our highest bet to a new higer bet
} else {
//do nothing because the amount won wasnt higher then the old amount 
}
}

Edited 4 Years Ago by DavidKroukamp: n/a

I can see I also missed an important part for this issue as well...

I have created a getter and a setter to hopefully grab the big jackpot and save it for reference later but inside I am drawing another blank as to how to return the big bet from inside a static method on a non static int variable.

This question has already been answered. Start a new discussion instead.