0

I can't get my winning to not be zero. And I don't see why.

import java.util.*;

public class Foothill 
{

   public static void main(String[] args) 
   {
      int loop = 1;
      int winnings =0 ;
      while ( loop != 0)
      {
      String s1 = PullOne();
      String s2 = PullOne();
      String s3 = PullOne();
      GetPayMultiplier(s1,s2,s3);
      Display(s1,s2,s3,winnings);
      }
      
   }
   

   public static int GetBet()
   {
      System.out.println("Welcome to our Slot Machine");

      int Bet;
      Scanner input = new Scanner(System.in);
   
      System.out.print("Please enter your bet from 1 - 100 here," +
      " or 0 to close : ");
      Bet = input.nextInt();

      while(Bet > 100)
      {
      System.out.println("\nYou have not entered a valid bet." +
      		"\n\nPlease try again :");
      Bet = input.nextInt();
      }
      while(Bet <= 0)
      {
         System.exit(0);
      }
      return Bet;
   }

   public static String PullOne()
   {
      String[] objects = { "Bar", "Cherries", "7", "Space" };
   
      int length = objects.length;
      int rand = (int)(Math.random()* length);
      String Pull = objects[rand] + " ";
      return Pull;
   }

   public static int GetPayMultiplier(String s1, String s2, String s3)
   {
      int Mult;
      
      if (s1 == "Cherries " && s2 != "Cherries ")
      {
         Mult = 3;   
      }
      else if (s1 == "Cherries " && s2 == "Cherries " && s3 != "Cherries ")
      {
         Mult = 10;
      }
      else if (s1 == "Cherries " && s2 == "Cherries " && s3 == "Cherries ")
      {
         Mult = 20;
      }
      else if (s1 == "Bar " && s2 == "Bar " && s3 == "Bar ")
      {
         Mult = 35;
      }
      else if (s1 == "7 " && s2 == "7 " && s3 == "7 ")
      {
         Mult = 50;
      }
      else 
      {
         Mult = 0;
      }
      return Mult;
   }

   public static void Display(String s1, String s2, String s3, int winnings)
   {
      winnings = GetBet() * GetPayMultiplier(s1,s2,s3);
      System.out.println(s1 + s2 + s3 + "\n" + winnings); 
      if( winnings == 0)
      {
         System.out.println("Sorry");
      }
      else
      {
         System.out.println("You won $" + winnings);
      }
      
   }
   
}
2
Contributors
1
Reply
4
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

You can't use == and != to test whether two Strings have the same sequence of letters. The == and != test whether they are exactly the same Object.
Th test you need to use is the equals method...
string1.equals(string2)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.