diff --git a/README.md b/README.md index 139597f..f6daf33 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,115 @@ +## 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. + +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. + +--- +## 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 + +Tasks: +Complete the Movie class (fields, constructor, getters/setters) + +Complete the Genre class (fields, constructor, getters/setters) + +Parse JSON data from getGenresList() into a list of Genre objects + +Display the list of genres to the user + +Fetch and return a list of movies by genreId and page number + +Display the genres of a specific movie + +Implement a console menu in Main to receive user input and display data + +Note: Detailed TODO comments are provided inside each of the above source files. + +--- +## 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 ✒️ +Parse the JSON returned by the `getMovieInfo` method into a MovieInfo entity, and then present the structured movie details based on the user‑provided movie ID. + +Advanced search (title, genre, year, rating, etc.) + +Sorting options for movies + +Save/load favorite movies to/from a file + +Improved console menu design + +GUI version using JavaFX + +--- +## Submission ⌛ +Deadline: May 1st (11 Ordibehesht) diff --git a/src/main/java/movie/apis/MovieService.java b/src/main/java/movie/apis/MovieService.java index 0f5015c..da23371 100644 --- a/src/main/java/movie/apis/MovieService.java +++ b/src/main/java/movie/apis/MovieService.java @@ -11,7 +11,7 @@ public class MovieService { private final static String GENRES_URL = "https://moviesapi.ir/api/v1/genres"; private static String MOVIES_BY_GENRE_URL = "https://moviesapi.ir/api/v1/genres/"; - private final static String MOVIE_INFO = "https://moviesapi.ir/api/v1/movies/{movie_id}";//todo fazel + private final static String MOVIE_INFO = "https://moviesapi.ir/api/v1/movies/{movie_id}"; private final static HttpClient client = HttpClient.newHttpClient(); private ArrayList moviesList; private ArrayList genresList; @@ -61,6 +61,31 @@ public class MovieService { return null; } + private String getMovieInfo(Long movieId) { + try { + + String url = MOVIE_INFO.replace("{movie_id}", movieId.toString()); + + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(url)) + .build(); + + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + + if (response.statusCode() == 200) { + System.out.println("Movie Info received successfully"); + return response.body(); + } else { + throw new IOException("HTTP error code: " + response.statusCode()); + } + + } catch (Exception e) { + System.out.println("!!Exception : " + e.getMessage()); + } + + return null; + } + // TODO: Write a method that parses the JSON returned by getGenresList() into a list of Genre objects. // TODO: Write a method that displays the list of genres.