Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
654e3b5ec4 |
@@ -28,5 +28,17 @@
|
|||||||
<version>2.17.2</version>
|
<version>2.17.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>25</source>
|
||||||
|
<target>25</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -54,27 +54,31 @@ 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-this.denominator*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 subtract(Rational r1, Rational r2) {
|
public static Rational subtract(Rational r1, Rational r2) {
|
||||||
// YOUR CODE HERE
|
int newNumerator= r1.numerator*r2.denominator-r1.denominator*r2.numerator;
|
||||||
return null; // Remove this line when implemented
|
int newDenominator=r1.denominator*r2.denominator;
|
||||||
|
return new Rational(newNumerator, newDenominator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
int newNumerator=r1.numerator*r2.numerator;
|
||||||
return null; // Remove this line when implemented
|
int newDenominator= r1.denominator*r2.denominator;
|
||||||
|
return new Rational(newNumerator, newDenominator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Instance method - this / other
|
// TODO: Instance method - this / other
|
||||||
@@ -83,13 +87,29 @@ public class Rational {
|
|||||||
// YOUR CODE HERE
|
// YOUR CODE HERE
|
||||||
// HINT: Division is multiplication by reciprocal
|
// HINT: Division is multiplication by reciprocal
|
||||||
// Don't forget to check if other.numerator is zero!
|
// 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
|
// TODO: Static method - r1 / r2
|
||||||
public static Rational divide(Rational r1, Rational r2) {
|
public static Rational divide(Rational r1, Rational r2) {
|
||||||
// YOUR CODE HERE
|
int newNumerator; int newDenominator;
|
||||||
return null; // Remove this line when implemented
|
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
|
// PROVIDED - String representation
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ public class Main {
|
|||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
// TODO: Get genre ID and page from user, then call movieService.displayMoviesByGenre()
|
// 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;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package movie.apis;
|
package movie.apis;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,15 +13,65 @@ public class Movie {
|
|||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
private String title;
|
private String title;
|
||||||
|
@JsonProperty("genre")
|
||||||
private List<String> genres;
|
private List<String> genres;
|
||||||
private List<String> images;
|
private List<String> images;
|
||||||
private String year;
|
private String year;
|
||||||
private String imdb_rating;
|
private String imdb_rating;
|
||||||
private String country;
|
private String country;
|
||||||
|
public Movie(){};
|
||||||
// TODO: Create a constructor with all fields
|
// TODO: Create a constructor with all fields
|
||||||
|
public Movie(Long id, String title, List<String> genres, List<String> 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
|
// 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
|
// TODO: Create getters and setters for all fields
|
||||||
|
public Long idGetter(){
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public String titleGetter(){
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
public List<String> genresGetter(){
|
||||||
|
return genres;
|
||||||
|
}
|
||||||
|
public List<String> 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<String> genres){
|
||||||
|
this.genres= new ArrayList<>(genres);
|
||||||
|
}
|
||||||
|
public void setImages(List<String> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package movie.apis;
|
package movie.apis;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
@@ -106,12 +108,16 @@ 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 json= getMoviesByGenreList(genreId, page);
|
||||||
|
ObjectMapper mapper= new ObjectMapper();
|
||||||
} catch (Exception e) {
|
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());
|
System.err.println("ERROR: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user