forked from ZeroAccess/CompleteJavaDevelopersCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
105 lines (85 loc) · 2.13 KB
/
Copy pathMain.java
File metadata and controls
105 lines (85 loc) · 2.13 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
package Polymorphism;
/**
* Created by robertsg on 12/1/2015.
*/
public class Main {
public static void main(String[] args) {
for (int i = 1; i < 11; i++) {
Movie movie = randomMovie();
System.out.println("Movie #" + i +
" : " + movie.getName() + "\n" +
"Plot: " + movie.plot() + "\n");
}
}
public static Movie randomMovie() {
int randomNumber = (int) (Math.random() * 5) + 1;
System.out.println("Random Number generated was: " + randomNumber);
switch (randomNumber) {
case 1:
return new Jaws();
case 2:
return new IndependenceDay();
case 3:
return new MazeRunner();
case 4:
return new StarWars();
case 5:
return new Forgettable();
}
return null;
}
}
class Movie {
private String name;
public Movie(String name) {
this.name = name;
}
public String plot() {
return "No plot here";
}
public String getName() {
return name;
}
}
class Jaws extends Movie {
public Jaws() {
super("Jaws");
}
@Override
public String plot() {
return "A shark eats lots of people";
}
}
class IndependenceDay extends Movie {
public IndependenceDay() {
super("Independence Day");
}
@Override
public String plot() {
return "Aliens attempt to take over planet earth";
}
}
class MazeRunner extends Movie {
public MazeRunner() {
super("Maze Runner");
}
@Override
public String plot() {
return ("Kids try and escape a maze");
}
}
class StarWars extends Movie {
public StarWars() {
super("Star Wars");
}
@Override
public String plot() {
return ("Imperial Forces try to take over the universe");
}
}
class Forgettable extends Movie {
public Forgettable() {
super("Forgettable");
}
// No plot method
}