-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovie.java
More file actions
178 lines (163 loc) · 5.18 KB
/
Movie.java
File metadata and controls
178 lines (163 loc) · 5.18 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
import java.util.Scanner;
import java.util.ArrayList;
/**
* Movie class holds information about a movie including title, director,
* up to three actors and a rating.
*
* @author (Bhavik Maneck)
* @version (v1)
*/
public class Movie
{
private String title;
private String director;
private ArrayList<String> actors;
private int rating;
/**
* Constructor for objects of class Movie with provided movie fields
*
* @param - movieTitle - title of movie, must not be blank
* @param - movieDirector - director of movie, must not be blank
* @param - movieActor1,movieActor2,movieActor3 - actor names of the movie, this implementation allows no actors to be provided
* @param - movieRating - integer between 1 and 10 inclusive
*
* @throws IllegalStateException if movieTitle or movieDirector is blank or nulll or movieRating is out of bounds
*/
public Movie(String movieTitle, String movieDirector, String movieActor1, String movieActor2, String movieActor3, int movieRating)
{
// Check if title is non-blank and director is non blank and rating is in bounds
// If any are invalid throw an exception and object is not created
if ((movieTitle.trim().length() == 0) || (movieTitle == null) ||
(movieDirector.trim().length() == 0) || (movieDirector == null) ||
(movieRating < 1) || (movieRating > 10))
{
throw new IllegalStateException("Title and Director must not be blank. Rating should be betwee 1 and 10.");
}
title = movieTitle;
director = movieDirector;
actors = new ArrayList<String>();
if (movieActor1.length() > 0)
{
actors.add(movieActor1);
}
if (movieActor2.length() > 0)
{
actors.add(movieActor2);
}
if (movieActor3.length() > 0)
{
actors.add(movieActor3);
}
rating = movieRating;
}
/*
* Displays all movie information
*/
public void displayMovieInformation()
{
System.out.print("Movie title: " + title + "\n");
System.out.print("Movie director: " + director + "\n");
if (actors.size() == 0)
{
System.out.print("No movie actors\n");
}
else
{
for (int i = 0; i < actors.size(); i++)
{
System.out.print("Movie actor " + (i+1) + ": " + actors.get(i) + "\n");
}
}
System.out.print("Movie rating: " + rating + "\n");
System.out.print("\n\n");
}
public ArrayList<String> getActors()
{
return actors;
}
public String getDirector()
{
return director;
}
public int getRating()
{
return rating;
}
public String getTitle()
{
return title;
}
/*
* Set the movie actors
*
* @param - actor1,actor2,actor3 - actor names of the movie
*
* @throws IllegalArgumentException if all actor names passed are blank
*/
public void setActors(String actor1, String actor2, String actor3)
{
// Make sure at least one actor string is non blank, if they all are blank throw exception
if ((actor1.trim().length() == 0) && (actor2.trim().length() == 0) && (actor3.trim().length() == 0))
{
throw new IllegalArgumentException("Must have at least one non-blank actor to set");
}
actors = new ArrayList<String>();
if (actor1.trim().length() > 0)
{
actors.add(actor1);
}
if (actor2.trim().length() > 0)
{
actors.add(actor2);
}
if (actor3.trim().length() > 0)
{
actors.add(actor3);
}
}
/*
* Set the movie director
*
* @param - newDirector - director name string of the movie
*
* @throws IllegalArgumentException if all director string is blank
*/
public void setDirector(String newDirector)
{
if (newDirector.trim().length() == 0) //check if director is blank string
{
throw new IllegalArgumentException("Director to set must not be blank\n");
}
director = newDirector;
}
/*
* Set the movie rating
*
* @param - newRating - integer rating number for the movie between 1 and 10 inclusive
*
* @throws IllegalArgumentException if
*/
public void setRating(int newRating)
{
if (newRating > 10 || newRating < 1) //check if rating is out of bounds
{
throw new IllegalArgumentException("Rating must be between 1 and 10\n");
}
rating = newRating;
}
/*
* Set the movie title
*
* @param - newTitle - title string of the movie
*
* @throws IllegalArgumentException if all title is blank
*/
public void setTitle(String newTitle)
{
if (newTitle.trim().length() == 0) //check if title is blank string
{
throw new IllegalArgumentException("Title to set must not be blank\n");
}
title = newTitle;
}
}