-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathAmusementParks.java
89 lines (74 loc) · 2.2 KB
/
AmusementParks.java
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
import java.util.Scanner;
abstract class Themepark {
int afee = 500, cfee = 300;
int calc(int n, int m) {
return (n * afee) + (m * cfee);
}
abstract void playGame(int j);
}
class Queensland extends Themepark {
int i;
Boolean games[] = new Boolean[30];
Queensland() {
System.out.println("Welcome to Queensland!");
for (i = 0; i < games.length; i++) {
games[i] = false;
}
}
void playGame(int j) {
if (games[j] == true) {
System.out.println("Error: You've already played this game");
} else {
System.out.println("Playing Game " + j + " at Queensland");
games[j] = true;
}
}
}
class Wonderla extends Themepark {
int i;
Boolean games[] = new Boolean[40];
Wonderla() {
System.out.println("Welcome to Wonderla!");
for (i = 0; i < games.length; i++) {
games[i] = false;
}
}
void playGame(int j) {
if (games[j] == true) {
System.out.println("Error: You've already played this game");
} else {
System.out.println("Playing Game " + j + " at Queensland");
games[j] = true;
}
}
}
public class AmusementParks {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i;
System.out.println("----Welcome to the Amusement Park----");
System.out.println("Select a park:\n1. Queensland\n2. Wonderla");
int c = sc.nextInt();
switch (c) {
case 1:
Queensland q = new Queensland();
System.out.print("Select a game (0 - 29): ");
while (sc.hasNextInt()) {
i = sc.nextInt();
q.playGame(i);
}
break;
case 2:
Wonderla w = new Wonderla();
System.out.print("Select a game (0 - 39): ");
while (sc.hasNextInt()) {
i = sc.nextInt();
w.playGame(i);
}
break;
default:
System.out.println("Invalid");
break;
}
}
}