forked from paulnguyen/code
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGumballMachine.java
More file actions
60 lines (49 loc) · 1.33 KB
/
GumballMachine.java
File metadata and controls
60 lines (49 loc) · 1.33 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
import java.lang.reflect.* ;
public class GumballMachine
{
private int cnt = 0;
private int coinValue = 0 ;
public GumballMachine(int count)
{
this.cnt = count ;
}
public void insertCoin( int value )
{
if ( coinValue < 50 ) {
coinValue += value ;
}
else {
System.out.println( "There is already enough coins in the slot" ) ;
}
}
public void turnTheCrank()
{
if ( coinValue == 50 ) {
coinValue = 0 ;
if ( cnt > 0 ) {
System.out.println( "Here is your Gumball! Enjoy!" ) ;
cnt-- ;
}
else {
System.out.println( "Sorry! We're out of Gumballs!" ) ;
}
}
else {
System.out.println( "Crank will not turn without enoush Coins!" ) ;
}
}
// Main Class - Dump Metadata
public static void main( String args[ ] )
{
System.out.println( "***** Class Bytecode Dump *****" ) ;
GumballMachine m = new GumballMachine(10) ;
Class gmClass = m.getClass() ;
Method gmMethods[] = gmClass.getMethods() ;
for ( int i=0; i <gmMethods.length; i++ )
{
Method theMethod = gmMethods[i] ;
String method = theMethod.toString() ;
System.out.println( method ) ;
}
}
}