Hi everyone, the first step in our Casino Program is to import any particular libraries that will aid in the program. This is a simple program output. The output asks for a valid bet. If the bet is valid, then the program allots ‘pay.’
If the bet is invalid, the program sends a loss message. So, let’s take a look at the program classes. Our first class, will be the ‘public class SlotMachine.’ It is the main, overarching class in the program. We begin the class, by creating a new Scanner object. Then we move into the main() method where we set an integer to store user winnings.
We then call on the TripleString class for pull results and then set integer bets to getBeth() method outcomes. While the user bet is not zero, we keep the game running, else we end the game. Our second class is the ‘public static int getBet() class.’ This class prompts the user for input and returns their bet amount as a functional return.
We begin the getBet() class by setting a variable, integer type to represent user bets. In a do-while loop, we prompt the user for their bet between 0 to 100. If the user bet is not in the 0 to 100 valid input, we prompt the user for a valid input.
And then, we return the user bet and pay the user for their betting. Our third class is the ‘public static String random class’ . This class produces and returns three random strings based on required probabilities set within our program.
We begin the class by first initializing all random strings members to empty. We set 1000 possible random strings for the program to use. We then create an algorithm that calculates the percentage of probability each random number will show up in the program. At the end of the class, we return the generated random strings that are valid. Our fourth class TripleString pull() class. This class initiates and returns a TripleString object to the user in the form of a slot pull.
We begin the class by first creating a TripleString object. We store three random strings in the TripleString object and at the end of the class, we return the TripleString object to the user. Our fifth class is the ‘public static int getPayMultiplier() class’. This class rewards the user with ‘pay’ for their gamble. We begin the class by first initializing any potential multipliers to zero. In an else-(else-if) loop we set each valid slot combination to match according to the appropriate multiplier and user ‘pay.’
At the end of the class, we return the multiplier for valid combination bet. Our sixth class is the ‘public static void display() class’. This class provides users with news about winnings. We begin the class in an else-if loop. If the user’s winnings are zero, we output “Sorry, you lost.” Else, we congratulate the user for winning and output their earnings in dollars.
Our seventh class is the ‘TripleString class’. This class stores String data and constructors. We begin the class by first defining the class constants of maximum and minimum lengths. We initialize three private String variables to store set items. We set the default constructors to empty and add a private helper method to determine whether a String is of legal input. We set all public boolean Strings in an else-if loop and validate whether they match the slot combinations for winning returns.
At the end of the class, we return all valid combinations of Strings as one string in an output. Our eighth and final class is the ‘public String displayWinnings() class’. This class returns individual win/ loss for each pull and total winnings for the entire game. We begin the class by first displaying to the user their individual winnings. We initialize winnings to zero and in a for-loop, calculate the both the individual result and the total winnings. At the