-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStore.java
More file actions
305 lines (284 loc) · 11.7 KB
/
Store.java
File metadata and controls
305 lines (284 loc) · 11.7 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*||||||||||||||||||||||||||||||||||||||
STORE CLASS
Allows for the creation of objects of
type Store
Contains methods for stores only found
in towns. The stores are able to have
different prices as allowed by the
constructors
||||||||||||||||||||||||||||||||||||*/
import cs1.Keyboard;
public class Store {
//========================
//===INSTANCE VARIABLES===
//========================
private static int foodP;
private static int ammoP;
private static int wheelsP;
private static int axlesP;
private static int tonguesP;
private static int foodS;
private static int ammoS;
private static int wheelsS;
private static int axlesS;
private static int tonguesS;
private static int answer;
private static int storeInt;
private static boolean storeBool;
private static boolean buyBool;
private static boolean sellBool;
//==================
//===CONSTRUCTORS===
//==================
public Store(int f, int a, int w, int ax, int t) {
foodP = f;
ammoP = a;
wheelsP = w;
axlesP = ax;
tonguesP = t;
foodS = (int)(f/2);
ammoS = (int)(a/2);
wheelsS = (int)(w/2);
axlesS = (int)(ax/2);
tonguesS= (int)(t/2);
}
//=============
//===METHODS===
//=============
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
enterStore
post: runs the store methods when in towns
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static void enterStore() {
String storeMenu = "";
storeMenu += "\nWelcome to the General Store! What would you like to do?\n";
storeMenu += "1:\tBuy supplies\n";
storeMenu += "2:\tSell supplies\n";
storeMenu += "3:\tLeave the store";
storeBool = true;
while (storeBool) {
System.out.println(storeMenu);
answer = Keyboard.readInt();
if (answer == 1) buyStore();
else if (answer == 2) sellStore();
else if (answer == 3) storeBool = false;
else System.out.println( "Invalid input" );
}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
buyStore
post: allows player to buy supplies
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static void buyStore() {
buyBool = true;
while (buyBool) {
String storeBuy = "";
storeBuy += "\nWhat would you like to buy?\n";
storeBuy += "\n" + Family.getSupplies() + "\n";
storeBuy += "Amount of Money:\t" + Family.john.getMoney() + "\n";
storeBuy += "1:\tFood\n";
storeBuy += "2:\tAmmunition\n";
storeBuy += "3:\tWheels\n";
storeBuy += "4:\tAxles\n";
storeBuy += "5:\tTongues\n";
storeBuy += "6:\tBack to store menu";
System.out.println(storeBuy);
answer = Keyboard.readInt();
if (answer == 1) buyFood();
else if (answer == 2) buyAmmo();
else if (answer == 3) buyWheels();
else if (answer == 4) buyAxles();
else if (answer == 5) buyTongues();
else if (answer == 6) buyBool = false;
else System.out.println( "Invalid input" );
}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sellStore
post: allows the player to sell supplies
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static void sellStore() {
sellBool = true;
while (sellBool) {
String storeSell = "";
storeSell += "\nWhat would you like to sell?\n";
storeSell += "\n" + Family.getSupplies() + "\n";
storeSell += "Amount of Money:\t" + Family.john.getMoney() + "\n";
storeSell += "1:\tFood\n";
storeSell += "2:\tAmmunition\n";
storeSell += "3:\tWheels\n";
storeSell += "4:\tAxles\n";
storeSell += "5:\tTongues\n";
storeSell += "6:\tBack to store menu";
System.out.println(storeSell);
answer = Keyboard.readInt();
if (answer == 1) sellFood();
else if (answer == 2) sellAmmo();
else if (answer == 3) sellWheels();
else if (answer == 4) sellAxles();
else if (answer == 5) sellTongues();
else if (answer == 6) sellBool = false;
else System.out.println( "Invalid input" );
}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
buyFood
post: runs the buying food prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static void buyFood() {
System.out.println( "Food goes for $" + foodP + " per parcel. 1 parcel contains 10 pounds of food" );
System.out.println( "How many parcels would you like to buy?" );
storeInt = Keyboard.readInt();
if ( ( storeInt >= 0 ) && ( (storeInt * foodP) <= Family.john.getMoney() ) ) {
Family.john.addFood( storeInt * 10 );
Family.john.subMoney( storeInt * foodP );
System.out.println( storeInt + " parcels bought" );
}
else if ( storeInt < 0 ) System.out.println("You can't buy a negative number of items");
else if ( (storeInt * foodP) > Family.john.getMoney() ) System.out.println("Not enough money");
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
buyAmmo
post: runs the buying ammo prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static void buyAmmo() {
System.out.println( "Ammo goes for $" + ammoP + " per box of bullets. 1 box contains 20 bullets" );
System.out.println( "How many boxes would you like to buy?" );
storeInt = Keyboard.readInt();
if ( ( storeInt >= 0 ) && ( (storeInt * ammoP) <= Family.john.getMoney() ) ) {
Family.john.addAmmo( storeInt * 20 );
Family.john.subMoney( storeInt * ammoP );
System.out.println( storeInt + " boxes of ammunition bought" );
}
else if ( storeInt < 0 ) System.out.println("You can't buy a negative number of items");
else if ( (storeInt * ammoP) > Family.john.getMoney() ) System.out.println("Not enough money");
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
buyWheels
post: runs the buying wheels prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static void buyWheels() {
System.out.println( "Wheels go for $" + wheelsP + " each" );
System.out.println( "How many wheels would you like to buy?" );
storeInt = Keyboard.readInt();
if ( ( storeInt >= 0 ) && ( (storeInt * wheelsP) <= Family.john.getMoney() ) ) {
Family.john.addWheels( storeInt );
Family.john.subMoney( storeInt * wheelsP );
System.out.println( storeInt + " wheels bought" );
}
else if ( storeInt < 0 ) System.out.println( "You can't buy a negative number of items" );
else if ( (storeInt * wheelsP) > Family.john.getMoney() ) System.out.println( "Not enough money" );
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
buyAxles
post: runs the buying axles prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static void buyAxles() {
System.out.println( "Axles go for $" + axlesP + " each" );
System.out.println( "How many axels would you like to buy?" );
storeInt = Keyboard.readInt();
if ( ( storeInt >= 0 ) && ( (storeInt * axlesP) <= Family.john.getMoney() ) ) {
Family.john.addAxles( storeInt );
Family.john.subMoney( storeInt * axlesP );
System.out.println( storeInt + " axles bought" );
}
else if ( storeInt < 0 ) System.out.println( "You can't buy a negative number of items" );
else if ( (storeInt * axlesP) > Family.john.getMoney() ) System.out.println( "Not enough money" );
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
buyTongues
post: runs the buying tongues prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static void buyTongues() {
System.out.println( "Tongues go for $" + tonguesP + " each" );
System.out.println( "How many tongues would you like to buy?" );
storeInt = Keyboard.readInt();
if ( ( storeInt >= 0 ) && ( (storeInt * tonguesP) <= Family.john.getMoney() ) ) {
Family.john.addTongues( storeInt );
Family.john.subMoney( storeInt * tonguesP );
System.out.println( storeInt + " tongues bought" );
}
else if ( storeInt < 0 ) System.out.println( "You can't buy a negative number of items" );
else if ( (storeInt * tonguesP) > Family.john.getMoney() ) System.out.println( "Not enough money" );
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sellFood
post: runs the selling food prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static void sellFood() {
System.out.println( "Food sells for $" + foodS + " per parcel. 1 parcel contains 10 pounds of food" );
System.out.println( "How many parcels would you like to sell?" );
storeInt = Keyboard.readInt();
if ( (storeInt >= 0) && ( (storeInt * 10) <= Family.john.getFood() ) ) {
Family.john.subFood( storeInt * 10 );
Family.john.addMoney( storeInt * foodS );
System.out.println( storeInt + " parcels sold" );
}
else if ( storeInt < 0 ) System.out.println("You can't sell a negative number of items");
else if ( (storeInt * 10) > Family.john.getFood() ) System.out.println("Not enough food to sell");
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sellAmmo
post: runs the selling ammo prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static void sellAmmo() {
System.out.println( "Ammunition sells for $" + ammoS + " per box. 1 box contains 20 bullets" );
System.out.println( "How many boxes of ammunition would you like to sell?" );
storeInt = Keyboard.readInt();
if ( (storeInt >= 0) && ( (storeInt * 20) <= Family.john.getAmmo() ) ) {
Family.john.subAmmo( storeInt * 20 );
Family.john.addMoney( storeInt * ammoS );
System.out.println( storeInt + " boxes of ammunition sold" );
}
else if ( storeInt < 0 ) System.out.println("You can't sell a negative number of items");
else if ( (storeInt * 20) > Family.john.getAmmo() ) System.out.println("Not enough bullets to sell");
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sellWheels
post: runs the selling wheels prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static void sellWheels() {
System.out.println( "Wheels sell for $" + wheelsS + " per wheel" );
System.out.println( "How many wheels would you like to sell?" );
storeInt = Keyboard.readInt();
if ( (storeInt >= 0) && ( (storeInt) <= Family.john.getWheels() ) ) {
Family.john.subWheels( storeInt );
Family.john.addMoney( storeInt * wheelsS );
System.out.println( storeInt + " wheels sold" );
}
else if ( storeInt < 0 ) System.out.println("You can't sell a negative number of items");
else if ( (storeInt) > Family.john.getWheels() ) System.out.println("Not enough wheels to sell");
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sellAxles
post: runs the selling axles prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static void sellAxles() {
System.out.println( "Axles sell for $" + axlesS + " per axle" );
System.out.println( "How many axles would you like to sell?" );
storeInt = Keyboard.readInt();
if ( (storeInt >= 0) && ( (storeInt) <= Family.john.getAxles() ) ) {
Family.john.subAxles( storeInt );
Family.john.addMoney( storeInt * axlesS );
System.out.println( storeInt + " axles sold" );
}
else if ( storeInt < 0 ) System.out.println("You can't sell a negative number of items");
else if ( (storeInt) > Family.john.getAxles() ) System.out.println("Not enough axles to sell");
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sellTongues
post: runs the selling tongues prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static void sellTongues() {
System.out.println( "Tongues sells for $" + tonguesS + " per tongues" );
System.out.println( "How many tongues would you like to sell?" );
storeInt = Keyboard.readInt();
if ( (storeInt >= 0) && ( (storeInt) <= Family.john.getTongues() ) ) {
Family.john.subTongues( storeInt );
Family.john.addMoney( storeInt * tonguesS );
System.out.println( storeInt + " tongues sold" );
}
else if ( storeInt < 0 ) System.out.println("You can't sell a negative number of items");
else if ( (storeInt) > Family.john.getTongues() ) System.out.println("Not enough tongues to sell");
}
}