-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdventure.java
More file actions
296 lines (201 loc) · 9.4 KB
/
Adventure.java
File metadata and controls
296 lines (201 loc) · 9.4 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
import java.util.Scanner;
public class Adventure {
public static void main(String[] args) {
boolean playing = true;
Scanner reader = new Scanner (System.in);
System.out.println
("Let's take a road trip!" + "\n" +
"What's your name?");
String name = reader.nextLine();
System.out.println("Welcome "+ name+ "! Our roadtrip begins in Detroit, Michigan.");
boolean keepAsking = true;
int mpg =0;
String car = "";
System.out.println("What car will we be taking? Please select a letter." + "\n" +
"A. 2016 Chrysler Pacifica B. 2010 Ford F150 " + "\n" +
"C. 2012 Toyota Prius D. 2014 Chevrolet Camero");
car = reader.nextLine();
if (car.equalsIgnoreCase("A"))
{ mpg = 28;
keepAsking = false;}
else if (car.equalsIgnoreCase("B"))
{ mpg = 21;
keepAsking = false;}
else if (car.equalsIgnoreCase("C"))
{ mpg = 48;
keepAsking = false; }
else if (car.equalsIgnoreCase("D"))
{mpg = 30;
keepAsking = false;}
else
System.out.println("Invalid entry.");
System.out.println("Nice choice!");
System.out.println("Your vehicle gets " + mpg + " mpg on the highway. We'll figure out how far we can go after we review the budget.");
System.out.println("We need to buy the road trip essentials- gas and snacks." + "\n" +
"How much money do you have to spend total? $ _____ (Please do not enter $ sign)");
int budget = reader.nextInt();
if (budget <0) {
System.out.println("Hey, this can't be negative! What's your budget?");
budget = reader.nextInt();
}
//not really necessary
/*if (budget > 2000)
System.out.println("Hey big spender, that's a little high for this road trip. Try again!");
budget = reader.nextInt();
*/
System.out.println("We have to decide how much of our budget to spend on snacks. On a scale of 1 to 10, how hungry are you? (10 is the hungriest!)");
int hunger = reader.nextInt();
if (hunger>10 || hunger <1){
System.out.println("Not a valid entry, please rate your hunger on a scale of 1 to 10.");
hunger = reader.nextInt();
}
//setting snack pay
int foodbudget= 0;
if (hunger > 8)
foodbudget = (int) (.3*budget);
else if (hunger > 6)
foodbudget = (int) (.2*budget);
else if (hunger > 2)
foodbudget = (int) (.1*budget);
else if( hunger > 0)
foodbudget = (int) (.05*budget);
// food items based on budget
System.out.println(
"Ok! Snacks have been bought. We spent $" + foodbudget + "." + "\n" +
"This is what we have in the cooler:");
int slimJimSpend;
int twinkieSpend;
int turkeySandSpend;
int rootBeerSpend;
slimJimSpend = (4 * foodbudget)/ 50;
twinkieSpend = (3 * foodbudget) / 25;
turkeySandSpend= (2 * foodbudget) / 4;
rootBeerSpend = (1 * foodbudget) / 1;
if (slimJimSpend > 0){
System.out.println(slimJimSpend + " Slim Jims" );
}
if (twinkieSpend > 0){
System.out.println(twinkieSpend + " Twinkies" );
}
if (turkeySandSpend > 0) {
System.out.println(turkeySandSpend + " Turkey Sandwiches");
}
if (rootBeerSpend > 0) {
System.out.println(rootBeerSpend + " Bottles of root beer");
}
//setting gas budget
int gasbudget = budget - foodbudget;
System.out.println("We have $" + gasbudget + " left to spend on gas.");
//miles to travel
int gasGallons = gasbudget / 3; //assuming gas price of $3 per gallon
int milesAvailable = gasGallons * mpg;
System.out.println("Time to hit the road! Should we drive north or south?");
String firstDirection;
reader.nextLine();
firstDirection = reader.nextLine();
if (firstDirection.equalsIgnoreCase("north")){
if (milesAvailable >=140){
System.out.println("We're heading north!");
System.out.println("Our first stop is Flint, Michigan. Population 99,763. Birthplace of filmmaker Michael Moore");
milesAvailable -= 140;
playing = false;
}
else if (milesAvailable > 70 && milesAvailable <140) {
System.out.println("Oops we have enough gas to reach our destination but not enough to make it home. You better stay home and work so you can have a bigger budget next time. Goodbye.");
playing = false;
}
else if (milesAvailable < 70){
System.out.println("You don't have anywhere near enough gas. You should have a staycation instead. Goodbye");
playing = false;
}
}
//south
if (firstDirection.equalsIgnoreCase("south")) {
if (milesAvailable >= 230){
System.out.println("We're heading south!");
System.out.println("Our first stop is Sandusky, Ohio. Population 25,340. Home of Cedar Point amusement park!");
milesAvailable -= 230;
}
if (milesAvailable > 115 && milesAvailable <230) {
System.out.println("Oops we have enough gas to reach our destination but not enough to make it home. You better stay home and work so you can have a bigger budget next time. Goodbye.");
playing = false;
}
if (milesAvailable < 115){
System.out.println("You don't have anywhere near enough gas. You should have a staycastion instead. Goodbye");
playing = false;
}
}
//east after north
System.out.println("Now should we travel East or West?");
String secondDirection = reader.nextLine();
if (firstDirection.equals("north")) {
if (secondDirection.equalsIgnoreCase("East") && milesAvailable >=443) {//calc as distance to TC and back to Detroit
System.out.println("We're heading East!");
System.out.println("We are now in Traverse City, Michigan. Population 15,018. Home to the annual Cherry Festival.");
System.out.println("Time to head back to Detroit.");
System.out.println("We made it to Detroit. See you next time");
playing = false;
}
if (milesAvailable > 190 && milesAvailable <443){
System.out.println("Oops we have enough gas to reach our destination but not enough to make it home. We'll head home instead. Goodbye.");
playing = false;
}
if (milesAvailable < 190) {
System.out.println("You don't have anywhere near enough gas. We'll head home instead. Goodbye");
playing = false;
}
// west after North
if (secondDirection.equalsIgnoreCase("west") && milesAvailable >=130) {
System.out.println("We're heading West!");
System.out.println("We are now in Port Huron, Michigan. Population 29,331. Its population grew rapidly after the 1850s due a high rate of immigration attracted by the successful shipbuilding and lumber trade.");
System.out.println("Time to head back to Detroit.");
System.out.println("We made it to Detroit. See you next time");
playing = false;
}
if (milesAvailable > 63 && milesAvailable < 130){
System.out.println("Oops we have enough gas to reach our destination but not enough to make it home. We'll head home instead. Goodbye.");
playing = false;
}
if (milesAvailable < 63) {
System.out.println("You don't have anywhere near enough gas. We'll head home instead. Goodbye");
playing = false;
}
}
if (firstDirection.equalsIgnoreCase("South")){
if (secondDirection.equalsIgnoreCase("west")){
if (milesAvailable >=574) {//calc as distance to TC and back to Detroit
System.out.println("We're heading West!");
System.out.println("We are now in Chicago, Illinois. Population 2.719 million. Grab a slice of pizza and head to Second City Comedy Club!");
System.out.println("Time to head back to Detroit.");
System.out.println("We made it to Detroit. See you next time");
playing = false;
}
if (milesAvailable > 313 && milesAvailable <574){
System.out.println("Oops we have enough gas to reach our destination but not enough to make it home. We'll head home instead. Goodbye.");
playing = false;
}
if (milesAvailable < 313) {
System.out.println("You don't have anywhere near enough gas. We'll head home instead. Goodbye");
playing = false;
}
}
if (secondDirection.equalsIgnoreCase("east")){
if (milesAvailable >=468) {
System.out.println("We're heading East!");
System.out.println("We are now in Pittsburgh, Pennsylvania. Population 305,841. Home of the 2016 Stanley Cup Champions");
System.out.println("Time to head back to Detroit.");
System.out.println("We made it to Detroit. See you next time");
playing = false;
}
if (milesAvailable > 182 && milesAvailable < 468){
System.out.println("Oops we have enough gas to reach our destination but not enough to make it home. We'll head home instead. Goodbye.");
playing = false;
}
if (milesAvailable < 182) {
System.out.println("You don't have anywhere near enough gas. We'll head home instead. Goodbye");
playing = false;
}
}
}
}
}