File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 1
1
import java .util .ArrayList ;
2
2
import java .util .HashMap ;
3
+ import java .util .Map ;
4
+ import java .util .Objects ;
3
5
4
6
/**
5
7
* Week2. A new class to do many of the calculations focusing on computing averages on movie
@@ -131,4 +133,19 @@ String getTitle(String id) {
131
133
// No title found
132
134
return "ID " + id + " NOT FOUND" ;
133
135
}
136
+ /*
137
+ * This method returns the movie ID of this movie.
138
+ * If the title is not found, return “NO SUCH TITLE.
139
+ * */
140
+ String getID (String title ) {
141
+ String result = "NO SUCH TITLE" ;
142
+
143
+ for (Map .Entry <String , String > entry : moviesIdAndTitles .entrySet ()) {
144
+ if (Objects .equals (title , entry .getValue ())) {
145
+ return entry .getKey ();
146
+ }
147
+ }
148
+
149
+ return result ;
150
+ }
134
151
}
You can’t perform that action at this time.
0 commit comments