update `Movie.java` and `Main.java` Main now has an example of usage of the `Movie` class.
prithugoswami prithugoswami524@gmail.com
Wed, 01 May 2019 00:18:39 +0530
2 files changed,
7 insertions(+),
12 deletions(-)
M
src/com/oocpro/tmdbdesktop/Main.java
→
src/com/oocpro/tmdbdesktop/Main.java
@@ -6,8 +6,10 @@
public class Main{ public static void main (String [] args)throws IOException{ Movie ring = new Movie(565); - System.out.println(ring.title); - System.out.println(ring.genres); + System.out.println(ring.title + " ("+ring.year+")"); + System.out.println("Plotline: " + ring.plotline); + System.out.println("Genres: " + ring.genres); + System.out.println("Rating: " + ring.rating); } }
M
src/com/oocpro/tmdbdesktop/Tmdb/Movie.java
→
src/com/oocpro/tmdbdesktop/Tmdb/Movie.java
@@ -22,26 +22,19 @@ public Movie(int id)throws IOException, MalformedURLException{
String geturl = MOVIEBASEURL+id+"?api_key="+Constants.API_KEY; InputStream res = (InputStream)new URL(geturl).getContent(); JSONObject movie = new JSONObject(new JSONTokener(res)); + JSONArray ja_genres = movie.getJSONArray("genres"); + Iterator genres_itr = ja_genres.iterator(); - Iterator genres_itr = ja_genres.iterator(); genres = new ArrayList<String>(); while(genres_itr.hasNext()){ JSONObject jo = (JSONObject)genres_itr.next(); genres.add(jo.getString("name")); } - - title = movie.getString("title"); year = movie.getString("release_date").substring(0,4); plotline = movie.getString("overview"); + rating = (float)movie.getDouble("vote_average"); } - - // String s_url=a_url+"search/movie?api_key="+api_key+"&query=%s"; - // String url=String.format(s_url,"CARS"); - // URL us1 = new URL(url); - // InputStream sres = (InputStream)us1.getContent(); - // JSONArray ja = new JSONArray(new JSONTokener(sres)); - // System.out.println(ja.toString(4)); }