Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HELP! PLEASE READ ALL INFO BEFORE RESPONDING TO QUESTION. NEED FULL COMPLETE ANS

ID: 3775675 • Letter: H

Question

HELP! PLEASE READ ALL INFO BEFORE RESPONDING TO QUESTION. NEED FULL COMPLETE ANSWER.

A slot machine is a gambling device that the user inserts money into then pulls a lever (or presses a button). The slot machine then displays a set of random images. If two or more of the images match, the user wins an amount of money that the slot machine dispenses back to the user.

Create a program that simulates a slot machine. The program should contain at least 2 methods (in addition to the main method) – one void method and one value-returning method – at least one of the methods should include arguments. When the program runs, it should do the following:

Ask the user to enter the amount of money he or she wants to enter into the slot machine. You should validate this input to make sure the user enters a positive value for the bid amount.

Instead of displaying images, the program will randomly select a word from the following list: Cherries, Oranges, Plums, Bells, Melons, Bars. To select a word, the program will generate a random number in the range of 0 through 5. If the number is 0, the selected word is Cherries; if the number is 1, the selected word is Oranges; and so forth. The program should randomly select a word from this list three times and display all three of the words.

If none of the randomly selected words match, the program will inform the user that he or she has won $0. If two of the words match, the program will inform the user that he or she has won two times the amount entered. If three of the words match, the program will inform the user that he or she has won three times the amount entered.

The program will ask whether or not the user wants to play again. If so, these steps are repeated. If not, the program displays the total amount of money entered into the slot machine for this session, the total amount won this session, and the net loss/gain.

In addition, the program will keep a record of the highest gain ever achieved while playing the game. The value will be written to a file between game sessions, so that it can be read from the file with each new session. If the user exceeds the record gain, a message indicating this is a record gain should be displayed, the value of the previous record gain should be displayed, and the new record gain should be stored. (Hint: If the file doesn’t exist, no record has been set yet.)

Please remember to use good programming practices – naming conventions, indentation, comments, etc. All currency output should be formatted appropriately.

Please attach the .java file for you program to your assignment submission in Blackboard.

Sample Program Output:

----jGRASP exec: java SlotMachine

Step Right Up and Try Your Luck at Kristin's Amazing Slot Machine! What is the amount of your bet this round? $1
Oranges Cherries Bars
Better luck next time! You won $0.00.

Would you like to play again? (Y/N): y
What is the amount of your bet this round? $2 Cherries Bells Oranges
Better luck next time! You won $0.00. Would you like to play again? (Y/N): y
What is the amount of your bet this round? $3 Plums Oranges Melons
Better luck next time! You won $0.00. Would you like to play again? (Y/N): n

Total Bets: $6.00
Total Winnings: $0.00
That's a Net Loss of $6.00 ----jGRASP: operation complete.

Explanation / Answer

//first program

package com.gambling;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class Gambler {
  
   public static void main(String[] args) throws IOException {
           boolean flag=true;  
       InputStreamReader r=new InputStreamReader(System.in);
       BufferedReader br=new BufferedReader(r);
       int moneyInt=0;
       System.out.println("Enter Money to Gamble");
       String money=br.readLine();
       if(money!=null || money!=""){
       moneyInt=Integer.parseInt(money);
       if(moneyInt<=0)
       {
           System.out.println("Please enter positive amount!");
           flag=false;
       }
       }else
       {
           System.out.println("Entered Amount is zero, Please enter it again!");
           flag=false;
       }
       if(flag){
       System.out.println("Let's play the game..with amount :"+moneyInt);
       GamlingMachine gm=new GamlingMachine();
       gm.playGame(moneyInt);
       }
   }
  
  
  
  

}

//second program

package com.gambling;

import java.util.Random;

public class GamlingMachine {

   public void playGame(int amount) {
       MapConstants mapConstants = new MapConstants();
       String firstRound = mapConstants.getGame(getRandom());
       String secondRound = mapConstants.getGame(getRandom());
       String thirdRound = mapConstants.getGame(getRandom());
       System.out.println("firstRound :" + firstRound);
       System.out.println("secondRound :" + secondRound);
       System.out.println("thirdRound :" + thirdRound);

       if (thirdRound.equals(secondRound) && thirdRound.equals(firstRound)) {
           System.out.println("All three cases match, you won :" + amount * 3);
       } else {
           if (thirdRound.equals(secondRound) || thirdRound.equals(firstRound)
                   || secondRound.equals(firstRound)) {
               System.out.println("Only two cases match, you won :" + amount
                       * 2);
           } else {
               System.out.println("Sorry! you lost all amount");
           }
       }

   }

   public int getRandom() {
       int max = 5, min = 0;
       Random random = new Random();
       return random.nextInt(max - min + 1) + min;
   }

}

//third program

package com.gambling;

import java.util.HashMap;
import java.util.Map;

public class MapConstants {
   Map<Integer,String> map;
   public MapConstants(){
       map=new HashMap<Integer,String>();
       map.put(0, "Cherries");
       map.put(1,"Oranges");
       map.put(2,"Plums");
       map.put(3,"Bells");
       map.put(4,"Melons");
       map.put(5,"Bars");
   }
   public String getGame(int num){
       return map.get(num);
   }
  
}


/*Output1:

Enter Money to Gamble
1
Let's play the game..with amount :1
firstRound :Bars
secondRound :Bells
thirdRound :Cherries
Sorry! you lost all amount

Output2:

Enter Money to Gamble
9
Let's play the game..with amount :9
firstRound :Cherries
secondRound :Cherries
thirdRound :Cherries
All three cases match, you won :27

output3:

Enter Money to Gamble
-7
Please enter positive amount!

*/