-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVendingMachine.java
More file actions
98 lines (76 loc) · 2.42 KB
/
Copy pathVendingMachine.java
File metadata and controls
98 lines (76 loc) · 2.42 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
/**
* Represents a Vending Machine
*
* @Ibrahim Shah (your name)
* @10/21/2020 (a version number or a date)
*/
public class VendingMachine
{
/**
* Number of cans to be present in the vending machine
*/
private int cans;
/**
* Number of tokens to be present in the vending machine
*/
private int tokens;
/**
* Whether or not a token is currently inserted into the machine (probably not)
*/
private boolean tokenPresent;
/**
* Creates a new vending machine with a given number of cans 0 tokens
*/
public VendingMachine(int numberOfCans){
cans = numberOfCans;
tokens = 0;
}
/**
* Creates a new vending machine with 10 soda cans and 0 tokens
*/
public VendingMachine(){
cans = 10;
tokens = 0;
}
/**
* Returns boolean telling user whether or not a token is inserted;
* if it is inserted, release one can, and set value to false
* @return whether it is true or false that a token is currently inserted into the machine
* @param inserted represents an inserted token
* @param notInserted represents a not inserted token
*
*/
//method token is inserted; if yes, drop can, return back to false, tokens++
//method getCans returns number of cans
//method insert cans increases number of cans
//method getTokens returns number of tokens
public int insertTokens(int tokensToBeInserted){
tokens = tokens+tokensToBeInserted;
cans = cans-tokensToBeInserted;
return tokens;
}
/**
* Returns the amount of cans present in the vending machine
* @return amount of cans currently present in the vending machine
*/
public int getCans(){
return cans;
}
/**
* Inserts cans into the vending machine
* @param numberOfCansToInsert is the number of cans, as an integer, you would like to insert into the vending machine
*
*/
public int insertCans(int numberOfCansToInsert){
cans = cans+numberOfCansToInsert;
return cans;
}
/**
*
* Returns number of tokens collected in vending machine
* @return number of total tokens collected in vending machine
*/
public int getTokens(){
return tokens;
}
}