## Third Assignment: Movie Explorer 🎬 + Rational Calculator 🧮 --- Welcome to Your Third Assignment in the Advanced Programming Course! This assignment consists of two separate parts. You must complete both parts. --- ## Part 1: Rational Class (Rational Numbers) In this part, you will implement a Rational class that supports basic mathematical operations. A `RationalTest` class is provided. +You can run it to verify that your implementation works correctly. +Use it to test your logic before submitting. Tasks: Define fields for numerator and denominator Implement addition, subtraction, multiplication, and division as instance methods Implement addition, subtraction, multiplication, and division as static methods Note: Detailed TODO comments are provided inside Rational.java. Do NOT modify the constructor, simplify logic, or completed methods. Only complete the TODO methods. --- ## Part 2: Movie Explorer 🎬 (Using API) In this part, you will develop a Java application that fetches movie data from an API and allows users to browse and search movies. ### Files Provided - `Movie.java` - `Genre.java` - `MovieService.java` - `Main.java` The `Genre` class is already implemented as a sample. You must design and implement the `Movie` class yourself (fields, constructors, getters, setters, toString if needed). We have already implemented two methods that call the API and return the raw JSON response as a `String`: - `getGenresList()` → calls the API and returns the list of genres in JSON format. - `getMoviesByGenreList(Long genreId, Long page)` → calls the API and returns the list of movies for a specific genre and page in JSON format. Do NOT modify: API URLs `getGenresList()` `getMoviesByGenreList()` Only complete the TODO methods. ### Your Tasks 1. Complete the `Movie` class (fields, constructor, getters, and setters). 2. Write a method that receives the JSON string returned by `getMoviesByGenreList()` and converts it into a `List`. 3. Write another method that displays the list of movies (for the selected genre) in a clean and readable format. 4. Implement a console menu in `Main` that allows the user to: - View the list of genres - Select a genre - View movies for the selected genre (with pagination) After completing `MovieService`, you must also complete the `Main` class so the menu works correctly. ### Note To understand what fields should exist in the `Genre` and `Movie` classes, it is recommended that you first call the two API methods once and inspect the raw JSON response. This will help you determine the exact structure of the data and define the appropriate class fields. We implemented JSON parsing using **Gson** in the project. However, the **Jackson dependency is also included**. If you prefer, you are allowed to use Jackson instead of Gson. --- ## Objectives ✏️ By completing this assignment, you will: Reinforce OOP concepts: class design, constructors, encapsulation, collections Practice instance methods vs. static methods Work with JSON parsing and REST APIs Design a simple console-based menu Improve Git workflow and project management ---- ## Prerequisites ✅ Git Java (version 23 or 25) Maven as a package manager --- ## Tasks Summary 📝 Fork the repository and clone it locally Create and switch to a development branch Complete Part 1 (Rational.java) following the TODO comments Complete Part 2 (Movie.java, Genre.java, MovieService.java, Main.java) following the TODO comments Ensure the code compiles and runs correctly Commit and push regularly Submit a pull request from development to main --- ## Evaluation Criteria ⚖️ Functionality: Code compiles and runs without errors; all features work correctly Code Quality: Clean, readable, well-structured code with proper naming Understanding: You must be able to explain your implementation --- ## Bonus Tasks ✒️ 1. Fetch and display movie information using movie ID Implement movie search by ID. User enters an ID, program displays complete movie details. ### ⚠️ First: Add Missing Fields to Movie Class The API returns more data than your current class supports. Add these fields: - `actors`, `awards`, `director`, `imdb_id`, `imdb_votes`, `metascore`, `plot`, `rated`, `released`, `runtime`, `type`, `writer` ### Implementation Steps: 1. **Complete `getMovieById(movieId)`** - Build request to: `https://api.meshcomp.ir/api/v1/movies/{movieId}` - If status 200 → return JSON body, else → return null 2. **Complete `displayMovieDetails(movieId)`** - Call `getMovieById()` → check for null - Use Gson to parse JSON to Movie object (after adding fields above) - Print formatted output (see example below) ### Example Output: ``` ======================================================================= THE SHAWSHANK REDEMPTION (1994) ======================================================================= Rating: 9.3/10 | Votes: 1,738,596 Director: Frank Darabont Cast: Tim Robbins, Morgan Freeman, Bob Gunton, William Sadler Genre: Crime, Drama Runtime: 142 min | Rated: R Country: USA | Released: 14 Oct 1994 Plot: Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency. Awards: Nominated for 7 Oscars. Another 19 wins & 30 nominations. ======================================================================= ``` --- ## References 📚 API (Replace placeholders with numbers): - genres: https://api.meshcomp.ir/api/v1/genres - movies: https://api.meshcomp.ir/api/v1/movies - movies (specifying the page): https://api.meshcomp.ir/api/v1/movies?page={pageId} - movies by genres: https://api.meshcomp.ir/api/v1/genres/{genreId}/movies?page={pageId} - details of a specific movie: https://api.meshcomp.ir/api/v1/movies/{movieId} Video Tutorials (watch before starting the assignment): [link](https://drive.meshcomp.ir/d/a29a5f6ea6484834bcf0/) Gson Tutorial: [`Gson` Reading and Parsing Data from a JSONObject](https://drive.meshcomp.ir/f/e8dea01f31b24cbca152/) Jackson Tutorial: [`Jackson` Parsing Json in Java Tutorial - Part 1 Jackson and Simple Objects](https://drive.meshcomp.ir/f/005d8f8fc19a44f4927b/) --- ## Submission ⌛ Deadline: May 1st (11 Ordibehesht)