Skip to content

. #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

. #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 14 additions & 26 deletions Report-Template.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,44 @@
# Project Title

Simple overview of use/purpose.
Search Movie & Actor.

## Description

An in-depth paragraph about your project and overview of use.
In this program, you can enter the name of your favorite actor and get information about them.

## Getting Started

...

### Dependencies

* Describe any prerequisites, libraries, OS version, etc., needed before installing program.
* ex. Windows 10
You should get Gradle version:8.6 in this program you need this libraries:ArrayList, JSONArray, JSONObject, IOException, InputStreamReader, net.URLConnection, io.BufferedReader, 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 intilij. 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 programming better.
KHAN ACADEMY, CODE SCHOOL, COURSERA.

## Authors

Contributors names and contact info

ex. Dominique Pizzie
ex. [@DomPizzie](https://twitter.com/dompizzie)
Sarina Hassani.

## Version History

* 0.2
* Various bug fixes and optimizations
* See [commit change]() or See [release history]()
* 0.1
* Initial Release
...

## License

This project is licensed under the [NAME HERE] License - see the LICENSE.md file for details
https://omdbapi.com (for Movie)
and https://api-ninjas.com/api/celebrity (for actor)

## Acknowledgments

Expand All @@ -59,4 +47,4 @@ Inspiration, code snippets, etc.
* [PurpleBooth](https://gist.github.com/PurpleBooth/109311bb0361f32d87a2)
* [dbader](https://github.com/dbader/readme-template)
* [zenorocha](https://gist.github.com/zenorocha/4526327)
* [fvcproductions](https://gist.github.com/fvcproductions/1bfc2d4aecb01a834b46)
* [fvcproductions](https://gist.github.com/fvcproductions/1bfc2d4aecb01a834b46)
57 changes: 54 additions & 3 deletions src/main/java/Actors.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.HttpURLConnection;
public class Actors {
public static final String API_KEY = "Your API_KEY"; // TODO --> add your api key about Actors here
public static final String API_KEY = "2oc2yj5UHqESdhSIvfVrpA==kXY0Y8KYuwuPgvNz"; // TODO --> add your api key about Actors here
String netWorth;
Boolean isAlive;
String gender;
String nationality;
String birthday;


public Actors(String netWorth, boolean isAlive){
public Actors(String netWorth, boolean isAlive, String gender, String nationality, String birthday){
//TODO --> (Write a proper constructor using the get_from_api functions)
this.netWorth = netWorth;
this.isAlive = isAlive;
this.gender = gender;
this.nationality = nationality;
this.birthday = birthday;
}
@SuppressWarnings({"deprecation"})
/**
Expand Down Expand Up @@ -46,19 +58,58 @@ public String getActorData(String name) {
public double getNetWorthViaApi(String actorsInfoJson){
//TODO --> (This function must return the "NetWorth")
double result = 0.0;
JSONArray array = new JSONArray(actorsInfoJson);
JSONObject info = array.getJSONObject(0);
result = info.getDouble("net_worth");
return result;
}

public boolean isAlive(String actorsInfoJson){
//TODO --> (If your chosen actor is alive it must return true otherwise it must return false)
boolean statues = false;
JSONArray array = new JSONArray(actorsInfoJson);
JSONObject info = array.getJSONObject(0);
statues = info.getBoolean("is_alive");
return statues;
}

public String getDateOfDeathViaApi(String actorsInfoJson){
//TODO --> (If your chosen actor is deceased it must return the date of death) -->
String date = "";
return date;
boolean statues = false;
JSONArray array = new JSONArray(actorsInfoJson);
JSONObject info = array.getJSONObject(0);
statues = info.getBoolean("is_alive");
if (statues == false) {
JSONObject Date = new JSONObject(actorsInfoJson);
date = Date.getString("death");
}
else {
date = "_";
}
return date;
}
public String getGender(String actorsInfoJson){
String gender = null;
JSONArray array = new JSONArray(actorsInfoJson);
JSONObject info = array.getJSONObject(0);
gender = info.getString("gender");
return gender;
}
public String getNationality(String actorsInfoJson){
String nationality = null;
JSONArray array = new JSONArray(actorsInfoJson);
JSONObject info = array.getJSONObject(0);
nationality = info.getString("nationality");
return nationality;
}
public String getBirthday(String actorsInfoJson){
String birthday = null;
JSONArray array = new JSONArray(actorsInfoJson);
JSONObject info = array.getJSONObject(0);


birthday = info.getString("birthday");
return birthday;
}
}
55 changes: 52 additions & 3 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,58 @@
import org.json.JSONArray;
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) {
// TODO --> complete main function
public static void main(String[] args) throws IOException {
// TODO --> complete main function.
runMenu();

}
public static void runMenu() {

public static void runMenu() throws IOException {
// TODO
Scanner scanner = new Scanner(System.in);
System.out.println("Hello");
System.out.println("Which one do you want?");
System.out.println("1-Mvie");
System.out.println("2-Actor/Actress");
int n = scanner.nextInt();
if (n == 1) {
System.out.println("Enter the name of the movie");
String name = scanner.next();
Movie movie = new Movie(new ArrayList<>(), "", 0, "", "", "", "", "");
String found = movie.getResponsive(movie.getMovieData(name));
while (true) {
if (found == "false") {
System.out.println("Movie not found, pleas try again!");
name = scanner.next();
found = movie.getResponsive(movie.getMovieData(name));
}
if (found == "true") {
System.out.println(movie.getImdbVotesViaApi((movie.getMovieData(name))));
System.out.println(movie.getRatingViaApi((movie.getMovieData(name))));
System.out.println(movie.getDirector(movie.getMovieData(name)));
System.out.println(movie.getWriter(movie.getMovieData(name)));
System.out.println(movie.getActorListViaApi(movie.getMovieData(name)));
System.out.println(movie.getGener(movie.getMovieData(name)));
System.out.println(movie.getLanguage(movie.getMovieData(name)));
break;
}
}
}
if (n == 2) {
System.out.println("Enter the name of the actor/actress");
String name = scanner.next();
Actors actors = new Actors("", false, "", "", "");
System.out.println(actors.getNetWorthViaApi(actors.getActorData(name)));
System.out.println(actors.isAlive(actors.getActorData(name)));
System.out.println(actors.getGender(actors.getActorData(name)));
System.out.println(actors.getNationality(actors.getActorData(name)));
System.out.println(actors.getDateOfDeathViaApi(actors.getActorData(name)));
System.out.println(actors.getBirthday(actors.getActorData(name)));
}
}
}
77 changes: 71 additions & 6 deletions src/main/java/Movie.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.List;

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<String> actorsList;
String rating;
String director;
String gener;
String writer;
String language;
String responsive;

public Movie(ArrayList<String> actorsList, String rating, int ImdbVotes){
public Movie(ArrayList<String> actorsList, String rating, int ImdbVotes, String director, String gener, String writer, String language, String responsive){
//TODO --> (Write a proper constructor using the get_from_api functions)
this.actorsList = actorsList;
this.rating = rating;
this.ImdbVotes = ImdbVotes;
this.director = director;
this.gener = gener;
this.writer = writer;
this.language = language;
this.responsive = responsive;
}

@SuppressWarnings("deprecation")
Expand All @@ -23,7 +41,7 @@ public Movie(ArrayList<String> 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);
BufferedReader reader = new BufferedReader(new InputStreamReader(Url.getInputStream()));
Expand All @@ -40,17 +58,64 @@ public int getImdbVotesViaApi(String moviesInfoJson){
//TODO --> (This function must change and return the "ImdbVotes" as an Integer)
// NOTICE :: you are not permitted to convert this function to return a String instead of an int !!!
int ImdbVotes = 0;
JSONObject info = new JSONObject(moviesInfoJson);
ImdbVotes = Integer.parseInt(info.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 = "";
return rating;
//String rating = null;
JSONObject info = new JSONObject(moviesInfoJson);
JSONArray ratings = info.getJSONArray("Ratings");
JSONObject rate = ratings.getJSONObject(0);
String value = rate.getString("Value");

return value;
}

public void getActorListViaApi(String movieInfoJson){
public ArrayList<String> getActorListViaApi(String movieInfoJson){
//TODO --> (This function must return the "Actors" in actorsList)
JSONObject info = new JSONObject(movieInfoJson);
//List<String> actors = new ArrayList<>();
String actors = info.getString("Actors");
String[] arraylist = actors.split(", ");
for (String i : arraylist) {
actorsList.add(i);
}

return actorsList;
}
public String getDirector(String movieInfoJson){
String director = null;
JSONObject info = new JSONObject(movieInfoJson);
director = info.getString("Director");
return director;
}
public String getGener(String movieInfoJson){
String gener = null;
JSONObject info = new JSONObject(movieInfoJson);
gener = info.getString("Genre");
return gener;
}
public String getWriter(String movieInfoJson){
String writer = null;
JSONObject info = new JSONObject(movieInfoJson);
writer = info.getString("Writer");
return writer;
}
public String getLanguage(String movieInfoJson){
String language = null;
JSONObject info = new JSONObject(movieInfoJson);
language = info.getString("Language");
return language;
}
public String getResponsive(String movieInfoJson){
String responsive = null;
JSONObject info = new JSONObject(movieInfoJson);
responsive = info.getString("Responsive");
return responsive;
}
}
3 changes: 2 additions & 1 deletion src/test/java/ActorsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class ActorsTest {

static String data1 , data2;
static Actors actors;
@BeforeAll
static void setUp() {
actors = new Actors("",false);
actors = new Actors("",false, "", "", "");
data1 = actors.getActorData("jennifer lawrence");
data2 = actors.getActorData("robin williams");
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/MovieTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down