2. In casinos from Monte Carlo to Las Vegas, one of the most common gambling dev
ID: 3730423 • Letter: 2
Question
2. In casinos from Monte Carlo to Las Vegas, one of the most common gambling devices is the slot machine-the "one-armed bandit." A typical slot machine has three wheels that spin around behind a narrow window. Each wheel is marked with the following symbols: CHERRY, LEMON, ORANGE, PLUM, BELL, and BAR. The window, however, allows you to see only one symbol on each wheel at a time. For example, the window might show the following configuration: BELL ORANGE BAR If you put a silver dollar into a slot machine and pull the handle on its side, the wheels spin around and eventually come to rest in some new configuration. If the configuration matches one of a set of winning patterns printed on the front of the slot machine, you get some money. If not, you're out a dollar. The following table shows a typical set of winning patterns, along with their associated payoffs: Patterns Payout BAR BAR BAR 250 BELL BELL BELL/BAR 20 PLUM PLUM PLUM/BAR 14 ORANGE ORANGE ORANGE/BAR 10 CHERRYCHERRY CHERRY CHERRY CHERRY CHERRY The notation BELL/BAR means that either a BELL or a BAR can appear in that position, and the dash means that any symbol at all can appear. Thus, getting a CHERRY in the first position is automatically good for two dollars, no matter what appears on the other wheels. The LEMON symbol never pays off, even if you happen to line up three of them.Explanation / Answer
Find the solution to the first problem attached. Here we have used the conditional statement to verify the condition is being met to win money or not.
Here a static final array is declared having names such as plum, cherry etc. Then a random number is generated, treated a an index of array and the element corresponding to that number is choosen assigned to the firstWheels.
Same is done for other two.
Then if user press y as ans to ques if he wants to play and has money > 0, then it rolls the wheels and gives the output which is compared for desired combination. If it matches any combination, money won is added to existing amount. else no money is added. And asks if player wants to play again. Each time it says yes, a doller is deducted from money.
Find the code below.
import java.util.Scanner;
import java.util.Random;
public class HelloWorld{
public static void main(String []args){
int money = 50;
String res;
String firstWheel;
String secondWheel;
String thirdWheel;
Hello h = new Hello();
System.out.println("Welcome to slots!!!");
System.out.println("You have "+money+"$");
do{
System.out.println("Would you like to play(Y/N)? ");
Scanner in = new Scanner(System.in);
res = in.nextLine();
if(res.equals("Y")){
money--;
System.out.println("You have "+money);
firstWheel = h.returnResult();
secondWheel = h.returnResult();
thirdWheel = h.returnResult();
System.out.println(firstWheel+" "+secondWheel+" "+thirdWheel+" -");
if(firstWheel.equals("bar")&&secondWheel.equals("bar")&&thirdWheel.equals("bar")){
System.out.println("You Won 250$!");
money = money + 250;
System.out.println("You have "+money);
}
else if((firstWheel.equals("bell"))&&(secondWheel.equals("bell"))&&(thirdWheel.equals("bar"))||(thirdWheel.equals("bell"))){
System.out.println("You Won 20$! ");
money = money + 20;
System.out.println("You have "+money);
}
else if(firstWheel.equals("plum")&&secondWheel.equals("plum")&&(thirdWheel.equals("bar")||thirdWheel.equals("plum"))){
System.out.println("You Won 14$!");
money = money + 14;
System.out.println("You have "+money);
}
else if(firstWheel.equals("orange")&&secondWheel.equals("orange")&&(thirdWheel.equals("bar")||thirdWheel.equals("orange"))){
System.out.println("You Won 10$!");
money = money + 10;
System.out.println("You have "+money);
}
else if(firstWheel.equals("cherry")&&secondWheel.equals("cherry")&&thirdWheel.equals("cherry")){
System.out.println("You Won 7$!");
money = money + 7;
System.out.println("You have "+money);
}
else if(firstWheel.equals("cherry")&&secondWheel.equals("cherry")){
System.out.println("You Won 5$!");
money = money + 5;
System.out.println("You have "+money);
}
else if(firstWheel.equals("cherry")){
System.out.println("You Won 2$!");
money = money + 2;
System.out.println("You have "+money);
}
else{
System.out.println("You Loose!");
System.out.println("You have "+money);
}
}}while((res.equals("Y"))&&(money>=1));
}
}
public class Hello{
public static String returnResult(){
final String[] fruit = {"cherry", "lemon", "Orange", "plum", "bar", "bell"};
Random random = new Random();
int index = random.nextInt(fruit.length);
return fruit[index];
}
}
Hope this will help.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.