diff --git a/pom.xml b/pom.xml
index 111501f..9524ff9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,5 +28,17 @@
2.17.2
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 25
+ 25
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/Rational/Rational.java b/src/main/java/Rational/Rational.java
index 7bd840e..c63a981 100644
--- a/src/main/java/Rational/Rational.java
+++ b/src/main/java/Rational/Rational.java
@@ -54,27 +54,31 @@ public class Rational {
// TODO: Instance method - this - other
// Formula: a/b - c/d = (a*d - c*b) / (b*d)
public Rational subtract(Rational other) {
- // YOUR CODE HERE
- return null; // Remove this line when implemented
+ int newNumerator= this.numerator*other.denominator-this.denominator*other.numerator;
+ int newDenominator= this.denominator*other.denominator;
+ return new Rational(newNumerator, newDenominator);
}
// TODO: Static method - r1 - r2
public static Rational subtract(Rational r1, Rational r2) {
- // YOUR CODE HERE
- return null; // Remove this line when implemented
+ int newNumerator= r1.numerator*r2.denominator-r1.denominator*r2.numerator;
+ int newDenominator=r1.denominator*r2.denominator;
+ return new Rational(newNumerator, newDenominator);
}
// TODO: Instance method - this * other
// Formula: (a/b) * (c/d) = (a*c) / (b*d)
public Rational multiply(Rational other) {
- // YOUR CODE HERE
- return null; // Remove this line when implemented
+ int newNumerator=this.numerator*other.numerator;
+ int newDenominator=this.denominator*other.denominator;
+ return new Rational(newNumerator, newDenominator);
}
// TODO: Static method - r1 * r2
public static Rational multiply(Rational r1, Rational r2) {
- // YOUR CODE HERE
- return null; // Remove this line when implemented
+ int newNumerator=r1.numerator*r2.numerator;
+ int newDenominator= r1.denominator*r2.denominator;
+ return new Rational(newNumerator, newDenominator);
}
// TODO: Instance method - this / other
@@ -83,13 +87,29 @@ public class Rational {
// YOUR CODE HERE
// HINT: Division is multiplication by reciprocal
// Don't forget to check if other.numerator is zero!
- return null; // Remove this line when implemented
+ int newNumerator;
+ int newDenominator;
+ if (other.numerator==0){
+ throw new IllegalArgumentException(other+" should not be zero");
+ }
+ else{
+ newNumerator= this.numerator*other.denominator;
+ newDenominator=this.denominator*other.denominator;
+ }
+ return new Rational(newNumerator, newDenominator);
}
// TODO: Static method - r1 / r2
public static Rational divide(Rational r1, Rational r2) {
- // YOUR CODE HERE
- return null; // Remove this line when implemented
+ int newNumerator; int newDenominator;
+ if (r2.numerator==0){
+ throw new IllegalArgumentException(r2.numerator+" shouldn't be zero");
+ }
+ else{
+ newNumerator=r1.numerator*r2.denominator;
+ newDenominator=r1.denominator*r2.numerator;
+ }
+ return new Rational(newNumerator, newDenominator); // Remove this line when implemented
}
// PROVIDED - String representation
diff --git a/src/main/java/movie/apis/Main.java b/src/main/java/movie/apis/Main.java
index f0e713d..8fb4e42 100644
--- a/src/main/java/movie/apis/Main.java
+++ b/src/main/java/movie/apis/Main.java
@@ -22,6 +22,10 @@ public class Main {
case 2:
// TODO: Get genre ID and page from user, then call movieService.displayMoviesByGenre()
+ Scanner input = new Scanner(System.in);
+ Long genreID= input.nextLong();
+ Long page=input.nextLong();
+ movieService.displayMoviesByGenre(genreID, page);
break;
diff --git a/src/main/java/movie/apis/Movie.java b/src/main/java/movie/apis/Movie.java
index 969774a..9fad84f 100644
--- a/src/main/java/movie/apis/Movie.java
+++ b/src/main/java/movie/apis/Movie.java
@@ -1,5 +1,8 @@
package movie.apis;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.ArrayList;
import java.util.List;
/**
@@ -10,15 +13,65 @@ public class Movie {
private Long id;
private String title;
+ @JsonProperty("genre")
private List genres;
private List images;
private String year;
private String imdb_rating;
private String country;
-
+ public Movie(){};
// TODO: Create a constructor with all fields
+ public Movie(Long id, String title, List genres, List images, String year, String imdb_rating, String country){
+ this.id=id; this.title=title; this.genres=genres; this.images=images; this.year=year; this.imdb_rating=imdb_rating; this.country=country;
+ }
// TODO: Create a simple constructor with id and title only
-
+ public Movie(Long id, String title){
+ this.id=id;this.title=title;
+ }
// TODO: Create getters and setters for all fields
+ public Long idGetter(){
+ return id;
+ }
+ public String titleGetter(){
+ return title;
+ }
+ public List genresGetter(){
+ return genres;
+ }
+ public List imagesGetter(){
+ return images;
+ }
+ public String yearGetter(){
+ return year;
+ }
+ public String Imdb_ratingGetter(){
+ return imdb_rating;
+ }
+ public String countryGetter(){
+ return country;
+ }
+ public void setId(Long id){
+ this.id=id;
+ }
+ public void setTitle(String title){
+ this.title=title;
+ }
+ public void setGenres(List genres){
+ this.genres= new ArrayList<>(genres);
+ }
+ public void setImages(List images){
+ this.images= new ArrayList<>(images); //for privacy stuff
+ }
+ public void setYear(String year){
+ this.year=year;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public void setImdb_rating(String imdb_rating) {
+ this.imdb_rating = imdb_rating;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/movie/apis/MovieService.java b/src/main/java/movie/apis/MovieService.java
index 3f053f5..ee2809c 100644
--- a/src/main/java/movie/apis/MovieService.java
+++ b/src/main/java/movie/apis/MovieService.java
@@ -1,5 +1,7 @@
package movie.apis;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
@@ -106,12 +108,16 @@ public class MovieService {
// TODO: Write your code here
// All parsing code must be inside try-catch
try {
- // Your code here
-
- } catch (Exception e) {
+ String json= getMoviesByGenreList(genreId, page);
+ ObjectMapper mapper= new ObjectMapper();
+ Movie m = mapper.readValue(json, Movie.class);
+ System.out.println("ID: " + m.idGetter() + "\nTitle: " + m.titleGetter() + "\nYear: " + m.yearGetter());
+ }
+ catch (Exception e) {
System.err.println("ERROR: " + e.getMessage());
}
- }
+ }
+
/**