π¬ "Movie Matcher": Find All Movies with a Given Rating Using Binary Search
Students will:
- Practice arrays and binary search in Java.
- Work with custom objects (
Movieclass). - Use Scanner for user input.
- Learn how to find multiple matches efficiently using Binary Search + Expansion.
- Implement clean, reusable code with methods.
You are building a mini tool for a movie recommendation system.
The platform has a sorted list of movies by rating (e.g., 1 to 5 stars).
A user enters their preferred rating (e.g., 4), and your system will return all movies with that exact rating.
-
Create a
Movieclass with:String titleint rating(1 to 5)
-
Create a sorted array of
Movieobjects (sorted by rating). -
Accept user input via
Scanner:- Prompt:
"Enter desired movie rating (1 to 5):"
- Prompt:
-
Use Binary Search to find one movie with that rating.
-
Then use left and right expansion to find all other matches.
-
Display all matched movie titles or a message if none found.
Enter desired movie rating (1 to 5): 4
π¬ Movies with 4-star rating:
- The Prestige
- Interstellar
- Inception
- Ask user for minimum rating, and return all movies with rating >= input.
- Sort unsorted movie list with Bubble Sort, then apply search.
- Java file:
MovieMatcher.java - Method:
List<Movie> findMoviesByRating(Movie[] movies, int rating) - Output clearly listing matches or "No results found"
- Arrays and custom classes
- Binary search
- Expansion for multiple matches
- Scanner for user input
- Clean code with modular methods
This reinforces what we covered in the Health Diagnosis Simulator, while using a fun and modern theme (movies). Great for engagement and retention.