diff --git a/.idea/misc.xml b/.idea/misc.xml
index 668048d..ed6ca53 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/Report-Template.md b/Report-Template.md
index 1db99da..bce0f87 100644
--- a/Report-Template.md
+++ b/Report-Template.md
@@ -1,57 +1,56 @@
# Project Title
-Simple overview of use/purpose.
+Movie and Actor database
## Description
-An in-depth paragraph about your project and overview of use.
+In this program, you enter the name of the movie or actor and receive the information of them.
## Getting Started
-
+ArrayList, JSONArray, JSONNObject
### Dependencies
-* Describe any prerequisites, libraries, OS version, etc., needed before installing program.
-* ex. Windows 10
+you shoud get Gradle version 8.5 in this program you nead thid libraries:
+ArrayList, JSONObject, IOException, InputStreamReader, net.URLConnection, io.BufferedReader and net.HttpURLConnection.
### Installing
-* How/where to download your program
-* Any modifications needed to be made to files/folders
+If you see this program you should install intellij and if you run this program you should install Gradle too.
### Executing program
-* How to run the program
-* Step-by-step bullets
-```
-code blocks for commands
-```
+After installing the program, enter the program file and open the main part, then press the green triangle next to the main function and the program will run like this.
+
## Help
-Any advise for common problems or issues.
-```
-command to run if program contains helper info
-```
+To learn better "API", you can refer to Jadi's YouTube channel. You can use the following sites to learn programing better.
+Code School... .
## Authors
Contributors names and contact info
-ex. Dominique Pizzie
+Mohaddeseh Ganjkhanlou: Student of SBU. ex. Dominique Pizzie
ex. [@DomPizzie](https://twitter.com/dompizzie)
## Version History
* 0.2
- * Various bug fixes and optimizations
- * See [commit change]() or See [release history]()
+ * Various bug fixes and optimizations
+ * See [commit change]() or See [release history]()
* 0.1
- * Initial Release
+ * Initial Release
## License
-This project is licensed under the [NAME HERE] License - see the LICENSE.md file for details
+https://omdbapi.com/ (for movie)
+
+https://api-ninjas.com/api/celebrity (for celebrity)
+
+https://www.bing.com/videos/riverview/relatedvideo?&q=how+to+take+API+with+JSON+in+java+on+grdle&&mid=D193646A9484D3F83B3DD193646A9484D3F83B3D&mmscn=mtsc&aps=0&FORM=VRDGAR
+https://www.bing.com/videos/riverview/relatedvideo?q=%D9%88%DB%8C%D8%AF%DB%8C%D9%88%D9%87%D8%A7%DB%8C%20%D8%AC%D8%A7%D8%AF%DB%8C%20%D8%AF%D8%B1%20%DB%8C%D9%88%D8%AA%DB%8C%D9%88%D8%A8&mid=07413B5CF9A564AAFA9D07413B5CF9A564AAFA9D&ajaxhist=0
## Acknowledgments
Inspiration, code snippets, etc.
diff --git a/src/main/java/.idea/.gitignore b/src/main/java/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/src/main/java/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/src/main/java/.idea/misc.xml b/src/main/java/.idea/misc.xml
new file mode 100644
index 0000000..6f29fee
--- /dev/null
+++ b/src/main/java/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/.idea/modules.xml b/src/main/java/.idea/modules.xml
new file mode 100644
index 0000000..122a905
--- /dev/null
+++ b/src/main/java/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/.idea/vcs.xml b/src/main/java/.idea/vcs.xml
new file mode 100644
index 0000000..c2365ab
--- /dev/null
+++ b/src/main/java/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/Actors.java b/src/main/java/Actors.java
index ebf8e2d..07bb9b8 100644
--- a/src/main/java/Actors.java
+++ b/src/main/java/Actors.java
@@ -3,13 +3,23 @@
import java.io.InputStreamReader;
import java.net.URL;
import java.net.HttpURLConnection;
+import org.json.JSONObject;
public class Actors {
- public static final String API_KEY = "Your API_KEY"; // TODO --> add your api key about Actors here
- String netWorth;
- Boolean isAlive;
+ public static final String API_KEY = "lx3V7SSX0UGbFy8DibPSfQ==fbNjG3un4zdTPqV3";
+ double netWorth;
+ String date_birth;
+ String gender;
+ double height;
+ Boolean status;
+ String date;
- public Actors(String netWorth, boolean isAlive){
- //TODO --> (Write a proper constructor using the get_from_api functions)
+ public Actors(double netWorth, String date_birth, String gender, double height, boolean status, String date){
+ this.netWorth = netWorth;
+ this.date_birth = date_birth;
+ this.gender = gender;
+ this.height = height;
+ this.status = status;
+ this.date = date;
}
@SuppressWarnings({"deprecation"})
/**
@@ -34,7 +44,7 @@ public String getActorData(String name) {
}
in.close();
- return response.toString();
+ return response.toString().substring(1, response.toString().length() - 1);
} else {
return "Error: " + connection.getResponseCode() + " " + connection.getResponseMessage();
}
@@ -45,20 +55,96 @@ public String getActorData(String name) {
}
public double getNetWorthViaApi(String actorsInfoJson){
//TODO --> (This function must return the "NetWorth")
- double result = 0.0;
- return result;
+ double netWorth = 0.0;
+ try {
+ JSONObject netWorthObject = new JSONObject(actorsInfoJson);
+ netWorth = netWorthObject.getDouble("net_worth");
+ System.out.println("Net Worth: " + netWorth);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return netWorth;
+ }
+
+ public String getDataOfBirth(String actorsInfoJson)
+ {
+ String date_birth = "";
+ try {
+ JSONObject Date = new JSONObject(actorsInfoJson);
+ if(Date.has("birthday"))
+ {
+ date_birth = Date.getString("birthday");
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return "Birthday: " + date_birth;
+ }
+ public String getGender(String moviesInfoJson)
+ {
+ String gender = "";
+ try
+ {
+ JSONObject Actors_Gender = new JSONObject(moviesInfoJson);
+ if(Actors_Gender.has("genre"))
+ {
+ gender = Actors_Gender.getString("Gender");
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return "Gender: " + gender;
+ }
+
+ public double getHeight(String actorsInfoJson)
+ {
+ double height = 0.0;
+ try
+ {
+ JSONObject height_object = new JSONObject(actorsInfoJson);
+ height = height_object.getDouble("height");
+ System.out.println("Height_Of_Person: " + height);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return height;
}
public boolean isAlive(String actorsInfoJson){
- //TODO --> (If your chosen actor is alive it must return true otherwise it must return false)
- boolean statues = false;
- return statues;
+ boolean status = false;
+ try {
+ JSONObject live = new JSONObject(actorsInfoJson);
+ status = live.getBoolean("is_alive");
+ System.out.println("Is Alive: "+ status);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return status;
}
public String getDateOfDeathViaApi(String actorsInfoJson){
//TODO --> (If your chosen actor is deceased it must return the date of death) -->
String date = "";
+ try {
+ JSONObject Date_Of_Death = new JSONObject(actorsInfoJson);
+ if(Date_Of_Death.has("death"))
+ {
+ date = Date_Of_Death.getString("death");
+ System.out.println("death: "+ date);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
return date;
}
-}
\ No newline at end of file
+
+ }
+
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index 92f3d9c..10e72e6 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -1,9 +1,74 @@
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Scanner;
+
public class Main {
- public static void main(String[] args) {
+ public static void main(String[] args) throws IOException {
// TODO --> complete main function
runMenu();
}
- public static void runMenu() {
- // TODO
+ public static void runMenu() throws IOException {
+ while (true)
+ {
+ Scanner input = new Scanner(System.in);
+ System.out.println("Hi, Welcome Movie and Actor database. In this program, you enter the name of the movie or actor and receive the information of them.");
+ System.out.println("1. Movie");
+ System.out.println("2. Actors");
+ int choice = input.nextInt();
+ switch (choice) {
+ case 1:
+ Movie movie_object = new Movie(new ArrayList<>(), "", 0, "", "", "", "", "", "", "", "", "", "", "");
+ System.out.println("Enter name of Movie: ");
+ Scanner Input_Movie = new Scanner(System.in);
+ String FilmName = Input_Movie.nextLine();
+ String check = movie_object.getMovieData(FilmName);
+ while (check.equals("Please check movies name!"))
+ {
+ FilmName = input.next();
+ check = movie_object.getMovieData(FilmName);
+
+ }
+ System.out.println(FilmName);
+ System.out.println(movie_object.getYear(movie_object.getMovieData(FilmName)));
+ System.out.println(movie_object.getRatingViaApi(movie_object.getMovieData(FilmName)));
+ System.out.println(movie_object.getReleased(movie_object.getMovieData(FilmName)));
+ System.out.println(movie_object.getGenre(movie_object.getMovieData(FilmName)));
+ System.out.println(movie_object.getRuntime(movie_object.getMovieData(FilmName)));
+ System.out.println(movie_object.getDirector(movie_object.getMovieData(FilmName)));
+ System.out.println(movie_object.getAuthor(movie_object.getMovieData(FilmName)));
+ System.out.println(movie_object.getPlot(movie_object.getMovieData(FilmName)));
+ System.out.println(movie_object.getLanguage(movie_object.getMovieData(FilmName)));
+ System.out.println(movie_object.getCountry(movie_object.getMovieData(FilmName)));
+ System.out.println(movie_object.getType(movie_object.getMovieData(FilmName)));
+ System.out.println(movie_object.getActorListViaApi(movie_object.getMovieData(FilmName)));
+ System.out.println(movie_object.getImdbVotesViaApi(movie_object.getMovieData(FilmName)));
+ break;
+ case 2:
+ Actors actors_object = new Actors(0.0, "", "", 0.0, false, "");
+ System.out.println("Enter name of Actor: ");
+ Scanner input_actor = new Scanner(System.in);
+ String ActorName = input_actor.next();
+ String Check = actors_object.getActorData(ActorName);
+ while (Check.equals("Please check actor name!"))
+ {
+ ActorName = input.next();
+ Check = actors_object.getActorData(ActorName);
+
+ }
+ System.out.println(ActorName);
+ System.out.println(actors_object.getNetWorthViaApi(actors_object.getActorData(ActorName)));
+ System.out.println(actors_object.getDataOfBirth(actors_object.getActorData(ActorName)));
+ System.out.println(actors_object.getGender(actors_object.getActorData(ActorName)));
+ System.out.println(actors_object.getHeight(actors_object.getActorData(ActorName)));
+ System.out.println(actors_object.isAlive(actors_object.getActorData(ActorName)));
+ System.out.println(actors_object.getDateOfDeathViaApi(actors_object.getActorData(ActorName)));
+ break;
+ default:
+ System.out.println("Invalid choice. Please select a valid option!");
+ }
+ }
+
}
}
\ No newline at end of file
diff --git a/src/main/java/Movie.java b/src/main/java/Movie.java
index 34b5d4c..0ef5d7d 100644
--- a/src/main/java/Movie.java
+++ b/src/main/java/Movie.java
@@ -1,3 +1,6 @@
+import org.json.JSONArray;
+import org.json.JSONObject;
+
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
@@ -5,13 +8,39 @@
import java.io.BufferedReader;
import java.util.ArrayList;
public class Movie {
- public static final String API_KEY = "Your API_KEY"; // TODO --> add your api key about Movie here
+ public static final String API_KEY = "4cc68bea"; // TODO --> add your api key about Movie here
int ImdbVotes;
ArrayList actorsList;
String rating;
+ String Year;
+ String Released;
+ String genre;
+ String Runtime;
+ String Director;
+ String name;
+ String Plot;
+ String language;
+ String country;
+ String Type;
+ String Actor;
+
- public Movie(ArrayList actorsList, String rating, int ImdbVotes){
- //TODO --> (Write a proper constructor using the get_from_api functions)
+
+ public Movie(ArrayList actorsList, String rating, int ImdbVotes, String Year, String Released, String genre, String Runtime, String Director, String name, String Plot, String language, String country, String Type, String Actor){
+ this.actorsList = actorsList;
+ this.ImdbVotes = ImdbVotes;
+ this.rating = rating;
+ this.Year = Year;
+ this.Released = Released;
+ this.genre = genre;
+ this.Runtime = Runtime;
+ this.Director = Director;
+ this.name = name;
+ this.Plot = Plot;
+ this.language = language;
+ this.country = country;
+ this.Type = Type;
+ this.Actor = Actor;
}
@SuppressWarnings("deprecation")
@@ -23,9 +52,9 @@ public Movie(ArrayList actorsList, String rating, int ImdbVotes){
*/
public String getMovieData(String title) throws IOException {
- URL url = new URL("https://www.omdbapi.com/?t="+title+"&apikey="+API_KEY);
+ URL url = new URL("https://www.omdbapi.com/?t="+title+"&apikey="+ API_KEY);
URLConnection Url = url.openConnection();
- Url.setRequestProperty("Authorization", "Key" + API_KEY);
+ Url.setRequestProperty("Authorization", "Key" + "4cc68bea1");
BufferedReader reader = new BufferedReader(new InputStreamReader(Url.getInputStream()));
String line;
StringBuilder stringBuilder = new StringBuilder();
@@ -33,24 +62,229 @@ public String getMovieData(String title) throws IOException {
stringBuilder.append(line);
}
reader.close();
- //handle an error if the chosen movie is not found
+ String Error = stringBuilder.toString();
+ if(Error.substring(Error.length() - 27).equals("\"Error\":\"Movie not found\""))
+ {
+ return "Please check movies name!";
+ }
return stringBuilder.toString();
}
public int getImdbVotesViaApi(String moviesInfoJson){
//TODO --> (This function must change and return the "ImdbVotes" as an Integer)
+ //ImdbVotes = Imdb_Votes.getInt("imdbVotes");
// NOTICE :: you are not permitted to convert this function to return a String instead of an int !!!
- int ImdbVotes = 0;
+ JSONObject Imdb_Votes = new JSONObject(moviesInfoJson);
+ int ImdbVotes = Integer.parseInt(Imdb_Votes.getString("imdbVotes").replace(",", ""));
return ImdbVotes;
}
public String getRatingViaApi(String moviesInfoJson){
- //TODO --> (This function must return the rating in the "Ratings" part
- // where the source is "Internet Movie Database") -->
- String rating = "";
+ JSONObject rate_object = new JSONObject(moviesInfoJson);
+ JSONArray rate_array = rate_object.getJSONArray("Ratings");
+ JSONObject rate = rate_array.getJSONObject(0);
+ String rating = rate.getString("Value");
return rating;
}
+ public String getYear(String moviesInfoJson)
+ {
+ String Year = "";
+ try
+ {
+ JSONObject Date_Of_Birth = new JSONObject(moviesInfoJson);
+ if(Date_Of_Birth.has("Year"))
+ {
+ Year = Date_Of_Birth.getString("Year");
+ System.out.println("Year: " + Year);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return Year;
+ }
- public void getActorListViaApi(String movieInfoJson){
- //TODO --> (This function must return the "Actors" in actorsList)
+ public String getReleased(String moviesInfoJson)
+ {
+ String Released = "";
+ try
+ {
+ JSONObject Film_Released = new JSONObject(moviesInfoJson);
+ if(Film_Released.has("Released"))
+ {
+ Released = Film_Released.getString("Released");
+ System.out.println("Released: " + Released);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return Released;
+ }
+
+ public String getGenre(String moviesInfoJson)
+ {
+ String genre = "";
+ try
+ {
+ JSONObject Film_Genre = new JSONObject(moviesInfoJson);
+ if(Film_Genre.has("Genre"))
+ {
+ genre = Film_Genre.getString("Genre");
+ System.out.println("Genre: " + genre);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return genre;
+ }
+
+ public String getRuntime(String moviesInfoJson)
+ {
+ String Runtime = "";
+ try
+ {
+ JSONObject Film_Runtime = new JSONObject(moviesInfoJson);
+ if(Film_Runtime.has("Runtime"))
+ {
+ Runtime = Film_Runtime.getString("Runtime");
+ System.out.println("Runtime: " + Runtime);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return Runtime;
+ }
+
+ public String getDirector(String moviesInfoJson)
+ {
+ String Director = "";
+ try
+ {
+ JSONObject Film_Director = new JSONObject(moviesInfoJson);
+ if(Film_Director.has("Director"))
+ {
+ Director = Film_Director.getString("Director");
+ System.out.println("Director: " + Director);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return Director;
+ }
+
+ public String getAuthor(String moviesInfoJson)
+ {
+ String name = "";
+ try
+ {
+ JSONObject Film_Author = new JSONObject(moviesInfoJson);
+ if(Film_Author.has("Writer"))
+ {
+ name = Film_Author.getString("Writer");
+ System.out.println("Writer: " + name);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return name;
}
-}
\ No newline at end of file
+
+ public String getPlot(String moviesInfoJson)
+ {
+ String Plot = "";
+ try
+ {
+ JSONObject Film_Plot = new JSONObject(moviesInfoJson);
+ if(Film_Plot.has("Plot"))
+ {
+ Plot = Film_Plot.getString("Plot");
+ System.out.println("Plot: " + Plot);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return Plot;
+ }
+
+ public String getLanguage(String moviesInfoJson)
+ {
+ String language = "";
+ try
+ {
+ JSONObject Film_Language = new JSONObject(moviesInfoJson);
+ if(Film_Language.has("Language"))
+ {
+ language = Film_Language.getString("Language");
+ System.out.println("Language: " + language);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return language;
+ }
+
+ public String getCountry(String moviesInfoJson)
+ {
+ String country = "";
+ try
+ {
+ JSONObject Product_Of_The_country = new JSONObject(moviesInfoJson);
+ if(Product_Of_The_country.has("Country"))
+ {
+ country = Product_Of_The_country.getString("Country");
+ System.out.println("Country: " + country);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return country;
+ }
+
+ public String getType(String moviesInfoJson)
+ {
+ String Type = "";
+ try
+ {
+ JSONObject Film_Type = new JSONObject(moviesInfoJson);
+ if(Film_Type.has("Type"))
+ {
+ Type = Film_Type.getString("Type");
+ System.out.println("Type: " + Type);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return Type;
+ }
+
+ public String getActorListViaApi(String movieInfoJson) {
+ String Actor = "";
+ JSONObject Film_Actor = new JSONObject(movieInfoJson);
+ Actor = Film_Actor.getString("Actors");
+ return "Actors:pro " + Actor;
+ }
+}
+
+
+
+
+
+
diff --git a/src/test/java/ActorsTest.java b/src/test/java/ActorsTest.java
index 457e28b..578207d 100644
--- a/src/test/java/ActorsTest.java
+++ b/src/test/java/ActorsTest.java
@@ -6,7 +6,7 @@ public class ActorsTest {
static Actors actors;
@BeforeAll
static void setUp() {
- actors = new Actors("",false);
+ actors = new Actors(0.0,"", "", 0.0, false, "");
data1 = actors.getActorData("jennifer lawrence");
data2 = actors.getActorData("robin williams");
}
diff --git a/src/test/java/MovieTest.java b/src/test/java/MovieTest.java
index ce8a14c..7a8d719 100644
--- a/src/test/java/MovieTest.java
+++ b/src/test/java/MovieTest.java
@@ -11,7 +11,7 @@ public class MovieTest {
@BeforeAll
static void setUp() throws IOException {
- movie = new Movie(new ArrayList<>(),"",0);
+ movie = new Movie(new ArrayList<>(),"",0, "", "", "", "", "", "", "", "", "", "", "");
data1 = movie.getMovieData("maze runner"); // movie
data2 = movie.getMovieData("this is us"); // series
}