remove printMovie method from MovieService and override tostring method in Movie class
This commit is contained in:
@@ -171,4 +171,21 @@ public class Movie {
|
|||||||
|
|
||||||
public void setPoster(String poster) { this.poster = poster; }
|
public void setPoster(String poster) { this.poster = poster; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String result = "=".repeat(70) + "\n"
|
||||||
|
+ " ".repeat(20) + this.getTitle() + " (" + this.getYear() + ")" + "\n"
|
||||||
|
+ "=".repeat(70) + "\n"
|
||||||
|
+ "Rating: " + this.getImdb_rating() + "/10" + " | " + "Votes: " + this.getImdb_votes() + "\n"
|
||||||
|
+ "Director: " + this.getDirector() + "\n"
|
||||||
|
+ "Cast: " + this.getActors() + "\n"
|
||||||
|
+ "Genre: " + this.getGenres() + "\n"
|
||||||
|
+ "Runtime: " + this.getRuntime() + " | " + "Rated: " + this.getRated() + "\n"
|
||||||
|
+ "Country: " + this.getCountry() + " | " + "Released: " + this.getReleased() + "\n"
|
||||||
|
+ "Plot: " + this.getPlot() + "\n"
|
||||||
|
+ "Awards: " + this.getAwards() + "\n"
|
||||||
|
+ "=".repeat(70);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -144,24 +144,10 @@ public class MovieService {
|
|||||||
JsonObject rootObject = JsonParser.parseString(jsonResponse).getAsJsonObject();
|
JsonObject rootObject = JsonParser.parseString(jsonResponse).getAsJsonObject();
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
Movie movie = gson.fromJson(rootObject, Movie.class);
|
Movie movie = gson.fromJson(rootObject, Movie.class);
|
||||||
printMovie(movie);
|
System.out.println(movie);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("ERROR parsing movie details: " + e.getMessage());
|
System.err.println("ERROR parsing movie details: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printMovie(Movie movie) {
|
|
||||||
System.out.println("=".repeat(70));
|
|
||||||
System.out.println(" ".repeat(20) + movie.getTitle() + " (" + movie.getYear() + ")");
|
|
||||||
System.out.println("=".repeat(70));
|
|
||||||
System.out.println("Rating: " + movie.getImdb_rating() + "/10" + " | " + "Votes: " + movie.getImdb_votes());
|
|
||||||
System.out.println("Director: " + movie.getDirector());
|
|
||||||
System.out.println("Cast: " + movie.getActors());
|
|
||||||
System.out.println("Genre: " + movie.getGenres());
|
|
||||||
System.out.println("Runtime: " + movie.getRuntime() + " | " + "Rated: " + movie.getRated());
|
|
||||||
System.out.println("Country: " + movie.getCountry() + " | " + "Released: " + movie.getReleased());
|
|
||||||
System.out.println("Plot: " + movie.getPlot());
|
|
||||||
System.out.println("Awards: " + movie.getAwards());
|
|
||||||
System.out.println("=".repeat(70));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user