Repository navigation
Expand file tree
/
Copy pathproject_33.java
More file actions
97 lines (80 loc) · 1.98 KB
/
Copy pathproject_33.java
File metadata and controls
97 lines (80 loc) · 1.98 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
/* Project 33 from Java Master Class, OOP Part 2: Polymorphism */
/* Super Class ********************************************************************** */
class Movie{
private String name;
public Movie(String name){
this.name = name;
}
public String plot(){
return "No plot here.";
}
public String getName(){
return name;
}
}
/* Sub Classes ************************************************************************/
class Jaws extends Movie{
public Jaws(){ //inherits name field and constructor from Movie super class
super("Jaws");
}
public String plot(){
return "Shark is really hungry.";
}
}
class IndependenceDay extends Movie{
public IndependenceDay(){
super("Independence Day");
}
public String plot(){
return "Will Smith inadvertantely blows up The White House.";
}
}
class PointBreak extends Movie{
public PointBreak(){
super("Point Break");
}
@Override
public String plot(){
return "Patric Swayze does a poor Ronald Reagan.";
}
}
class HellRaiser extends Movie{
public HellRaiser(){
super("Hellraiser");
}
@Override
public String plot(){
return "Fully grown goths give each other fun nicknames.";
}
}
class ForgetableMovie extends Movie{
public ForgetableMovie(){
super("Forgetable Movie");
}
}
public class project_33{
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');
}
}
/* Random Movie generator ******************************************************/
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 PointBreak();
case 4:
return new HellRaiser();
case 5:
return new ForgetableMovie();
}
return null;
}
}