Merge pull request 'Implement movie explorer API features' (#1) from develop into main

Reviewed-on: #1

100/100
This commit was merged in pull request #1.
This commit is contained in:
2026-06-12 13:52:04 +00:00
5 changed files with 71 additions and 29 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" project-jdk-name="25" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_25" project-jdk-name="ms-25" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>
+14 -14
View File
@@ -54,42 +54,42 @@ public class Rational {
// TODO: Instance method - this - other // TODO: Instance method - this - other
// Formula: a/b - c/d = (a*d - c*b) / (b*d) // Formula: a/b - c/d = (a*d - c*b) / (b*d)
public Rational subtract(Rational other) { public Rational subtract(Rational other) {
// YOUR CODE HERE int newNumerator = this.numerator * other.denominator - other.numerator * this.denominator;
return null; // Remove this line when implemented int newDenominator = this.denominator * other.denominator;
return new Rational(newNumerator, newDenominator);
} }
// TODO: Static method - r1 - r2 // TODO: Static method - r1 - r2
public static Rational subtract(Rational r1, Rational r2) { public static Rational subtract(Rational r1, Rational r2) {
// YOUR CODE HERE return r1.subtract(r2);
return null; // Remove this line when implemented
} }
// TODO: Instance method - this * other // TODO: Instance method - this * other
// Formula: (a/b) * (c/d) = (a*c) / (b*d) // Formula: (a/b) * (c/d) = (a*c) / (b*d)
public Rational multiply(Rational other) { public Rational multiply(Rational other) {
// YOUR CODE HERE int newNumerator = this.numerator * other.numerator;
return null; // Remove this line when implemented int newDenominator = this.denominator * other.denominator;
return new Rational(newNumerator, newDenominator);
} }
// TODO: Static method - r1 * r2 // TODO: Static method - r1 * r2
public static Rational multiply(Rational r1, Rational r2) { public static Rational multiply(Rational r1, Rational r2) {
// YOUR CODE HERE return r1.multiply(r2);
return null; // Remove this line when implemented
} }
// TODO: Instance method - this / other // TODO: Instance method - this / other
// Formula: (a/b) ÷ (c/d) = (a*d) / (b*c) // Formula: (a/b) ÷ (c/d) = (a*d) / (b*c)
public Rational divide(Rational other) { public Rational divide(Rational other) {
// YOUR CODE HERE if (other.numerator == 0)
// HINT: Division is multiplication by reciprocal throw new ArithmeticException("Cannot divide by zero");
// Don't forget to check if other.numerator is zero! int newNumerator = this.numerator * other.denominator;
return null; // Remove this line when implemented int newDenominator = this.denominator * other.numerator;
return new Rational(newNumerator, newDenominator);
} }
// TODO: Static method - r1 / r2 // TODO: Static method - r1 / r2
public static Rational divide(Rational r1, Rational r2) { public static Rational divide(Rational r1, Rational r2) {
// YOUR CODE HERE return r1.divide(r2);
return null; // Remove this line when implemented
} }
// PROVIDED - String representation // PROVIDED - String representation
+5 -5
View File
@@ -21,15 +21,15 @@ public class Main {
break; break;
case 2: case 2:
// TODO: Get genre ID and page from user, then call movieService.displayMoviesByGenre() Long genreId = getLongInput("Enter genre ID: ");
Long page = getLongInput("Enter page number: ");
movieService.displayMoviesByGenre(genreId, page);
break; break;
case 3: case 3:
// TODO (BONUS): Get movie ID from user, then call movieService.displayMovieDetails() Long movieId = getLongInput("Enter movie ID: ");
movieService.displayMovieDetails(movieId);
break; break;
case 0: case 0:
+31 -6
View File
@@ -15,10 +15,35 @@ public class Movie {
private String year; private String year;
private String imdb_rating; private String imdb_rating;
private String country; private String country;
public Movie(Long id, String title, List<String> genres, List<String> images, String year, String imdb_rating, String country) {
// TODO: Create a constructor with all fields this.id = id;
this.title = title;
// TODO: Create a simple constructor with id and title only this.genres = genres;
this.images = images;
// TODO: Create getters and setters for all fields this.year = year;
this.imdb_rating = imdb_rating;
this.country = country;
}
public Movie(Long id, String title) {
this.id = id;
this.title = title;
}
public Long getId() {
return id;
}
public String getTitle() {
return title;
}
public List<String> getGenres() {
return genres;
}
public String getYear() {
return year;
}
public String getImdbRating() {
return imdb_rating;
}
public String toString() {
return id + ": " + title + " (" + year + ")";
}
} }
+20 -3
View File
@@ -106,9 +106,26 @@ public class MovieService {
// TODO: Write your code here // TODO: Write your code here
// All parsing code must be inside try-catch // All parsing code must be inside try-catch
try { try {
// Your code here String jsonResponse = getMoviesByGenreList(genreId, page);
if (jsonResponse == null || jsonResponse.isEmpty()) {
} catch (Exception e) { System.out.println("No response received.");
return;
}
JsonObject rootObject = JsonParser.parseString(jsonResponse).getAsJsonObject();
JsonArray moviesArray = rootObject.getAsJsonArray("movies");
int total = rootObject.get("total").getAsInt();
int totalPages = rootObject.get("total_pages").getAsInt();
Type movieListType = new TypeToken<ArrayList<Movie>>() {}.getType();
Gson gson = new Gson();
List<Movie> movies = gson.fromJson(moviesArray, movieListType);
System.out.println("Movies:");
for (Movie movie : movies) {
System.out.println("ID: " + movie.getId() + " | " + movie.getTitle() + " (" + movie.getYear() + ")");
}
System.out.println("Total movies: " + total);
System.out.println("Total pages: " + totalPages);
}
catch (Exception e) {
System.err.println("ERROR: " + e.getMessage()); System.err.println("ERROR: " + e.getMessage());
} }
} }