-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlotMachine.java
More file actions
165 lines (141 loc) · 4.47 KB
/
SlotMachine.java
File metadata and controls
165 lines (141 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment2;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
/**
* This class is a casino slot machine
* when user load money in the machine, it automatically calculate balance and
* once three random fruits are set, winning prize show up on the screen as a output
*
* @author Sungwoong Pyeon, 000734962
*/
public class SlotMachine {
// ** set balance of machine to 0 ** //
private double balance = 0;
// ** set the money when user load in the machine ** //
private final double load = 1.00;
// ** set a quater $0.25 ** //
private final double aQuater = 0.25;
// ** set item1(fruit1) ** //
private int item1, item2, item3;
/**
* to get current balance of machine
*
* @return balance
*/
public double getBalance() {
return balance;
}
/**
* to load $1.00 in the slot machine
*/
public void loadMoney() {
this.balance = (this.balance + this.load);
System.out.println("Now you load $1.00" + ", $" + this.balance);
System.out.println("------------------------");
}
/**
* to get item1 and this is encapsulated
* @return item1
*/
public int getItem1() {
return item1;
}
/**
* to get item2 and this is encapsulated
* @return item2
*/
public int getItem2() {
return item2;
}
/**
* to get item3 and this is encapsulated
* @return item3
*/
public int getItem3() {
return item3;
}
/**
*
* @param item which is set randomly from spinwheel()
* @return fruit which is converted from random item number to fruit real name
*/
public String getFruit(int item) {
String fruit = new String[]{"orange", "watermelon", "pear", "cherry", "grapes"}[item];
return fruit;
}
/**
*
* to print out fruit picture on the canvas
* @param fruit name of fruit which is set from getFruit()
* @return image file 1
*/
public Image display( String fruit) {
Image img1;
img1 = new Image("file:C:\\Users\\tjddn\\Documents\\NetBeansProjects\\assignment2\\src\\images\\" + fruit + ".png");
return img1;
}
/**
* Once user play the game, no matter how much money user win, machine automatically subtract $0.25 from the balance
*/
public void spendQuater() {
if (balance != 0) {
balance -= aQuater;
}
}
/**
* to set each of items to the random number from 0 to 4
*/
public void spinwheel() {
item1 = (int) (Math.random() * 4);
item2 = (int) (Math.random() * 4);
item3 = (int) (Math.random() * 4);
}
/**
* to check if user win or not
* @return number of fruits of the same shape
*/
public int win() {
if (item1 == item2 && item2 == item3 && item1 == item3) {
return 3;
} else if (item1 == item2 || item2 == item3 || item1 == item3) {
return 2;
} else {
return 0;
}
}
/**
* to show the message and add prize and balance
* @param checkWin number of fruits of the same shape
*/
public void showPrize(int checkWin) {
if (checkWin == 2) {
System.out.println("You Win!! Prize is $1.00 ");
System.out.println("------------------------");
balance += 1.00;
} else if (checkWin == 3) {
System.out.println("You Win!! Prize is $3.00 ");
System.out.println("------------------------");
balance += 3.00;
} else {
System.out.println("You did not get any prize, Sorry");
System.out.println("------------------------");
balance += 0;
}
}
/**
* to make sure that program will be never working when machine does not have balance
* @return boolean (balance > 0 or balance <= 0)
*/
public boolean balanceLess0() {
if (balance <= 0) {
return true;
} else {
return false;
}
}
}