Skip to content

Commit 26aa027

Browse files
committed
Week2. getID. This method returns the movie ID
1 parent 038369d commit 26aa027

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Week2/src/SecondRatings.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import java.util.ArrayList;
22
import java.util.HashMap;
3+
import java.util.Map;
4+
import java.util.Objects;
35

46
/**
57
* Week2. A new class to do many of the calculations focusing on computing averages on movie
@@ -131,4 +133,19 @@ String getTitle(String id) {
131133
// No title found
132134
return "ID " + id + " NOT FOUND";
133135
}
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+
}
134151
}

0 commit comments

Comments
 (0)