diff --git a/README.md b/README.md index 3c5803e..019a098 100644 --- a/README.md +++ b/README.md @@ -2,76 +2,18 @@ ## Introduction -In this assignment, you will create a simulation of Netflix. The program should allow users to create and manage their accounts and profiles, browse movies, and manage their movies. The program should be designed using object-oriented programming principles. - -## Objectives -- Review the concepts of object-oriented programming (OOP) and utilize them correctly -- Familiarize yourself with the concept of Encapsulation -- Learn the difference between Static and Instance variables -- Learn about polymorphism -- Get familiar with Interfaces in java -- Get familiar with UML diagrams -- Use Git for version control and collaborate on a codebase -- Write a report on the assignment +In this assignment,i created an app that is simulation of Netflix.users can manage the information on their profiles and the movies +they watched and search through them , and give them a rating and .... ## Tasks -1. Fork this repository and clone the fork to your local machine. Ensure to create a new Git branch before starting your work -2. Complete the following classes by adding the required parameters and implementing the predefined functions: `Movie`, `User`, `TVShow`, `NetflixService`. -3. In the `runMenu()` function of the `Main` class, Implement an interactive menu in the command line that allows users to use the functionalities of the program. -4. Your menu should allow new Users to create an account by providing a username and a password. Prevent new users from choosing a previously taken username. Authenticate each user before logging in -5. Your program should keep a list of all users (and their favorite or previously seen movies), and all movies. -6. You should use inheritance efficiently for the `Movie` class (Read the comments). It has an attribute more than the `TVShow` class (`length`) which is the length of the movie. -7. Implement the predefined methods in the `NetflixService` class, based on the explanations below: - - `createAccount`: Creates an account for a user with the provided username and password. A unique password should be provided. - - `login`: Performs any needed operations of the login process, if there exists any user with such username and password. - - `logout`: Performs any needed operations of the logout process (exiting from the account), if a user is logged in to their account. - - `searchByTitle`: Searches among all the movies by the provided title. Returns an arraylist of the found movies. - - `searchByGenre`: Searches among all the movies by the provided genre. Returns an arraylist of the found movies. - - `searchByReleaseYear`: Searches among all the movies by the provided release year. Returns an arraylist of the found movies. -8. Implement the predefined methods in the `User` class, based on the explanations below: - - `searchByTitle`: Searches among the user's favorite or previously seen movies, by the provided title. Returns an arraylist of the found movies. - - `searchByGenre`: Searches among the user's favorite or previously seen movies, by the provided genre. Returns an arraylist of the found movies. - - `searchByReleaseYear`: Searches among the user's favorite or previously seen movies, by the provided release year. Returns an arraylist of the found movies. - - `addToFavorites`: Adds the provided TV show to the list of the favorite movies of the user. - - `viewFavorites`: Shows the list of the favorite movies of the user. - - `getRecommendations`: Gives the list of the user's recommended movies. Returns this list as an arraylist. -9. Commit your changes, push your commits to your own fork on Github, and create a pull request to merge your changes to the `main` branch of your own fork on Github. -10. Write a report. Your report should contain a UML diagram for each class. - -## Notes -- The code provided in this repository gives you a template to work with and build your project. You are allowed to: - - Add new functions and classes to your code wherever you see fit. - - Change and swap the predefined functions as you wish, as long as the program satisfies all the requirements. - -- Your report should focus on the structure you choose for each different class, as well as the OOP principles you follow while designing your project. Describe the design of your program, including the classes, objects, methods, and attributes. - -- If you implement any bonus features, be sure to include additional details about them in your report. - -## Evaluation -- Your code should compile and run without any errors -- Your code should be well-organized, readable, properly commented, and follows clean code principles -- Your code should follow OOP principles and correctly use Java access modifiers -- OOP concepts like polymorphism and encapsulation should be efficiently used in your code. -- You should use Git for version control and include meaningful commit messages (The `main` branch will be used for evaluation) - -**Attention: Using ChatGPT or any other AI generative model for any section of the assignment will result in a score of 0 without any warnings.** +1.for the netflixServices i used many different type of searching for movies like their genre ,title or release year .it will show +you a list of the movies that you as the user entered . +2.for the movies class it extends TVShow class and i just added length for each movie +3.in user we have the getRecommendation method that i think it is the only method that worths explaining and based on your ;last favourite +movie it will recommend you similar movies from the same genre if they have higher points than 8.0 . +4.finally i wrote some taste cases and wrote this report . ## Bonus Objectives -1. Perform Input Validation: Ensure the data or information entered by a user or system is correct, complete, and appropriate for the intended use. - -2. Extend the available classes to create a more secure login system. Use a hashing algorithm to hash the user's password. Give a brief explanation of the hashing process in your report. - -3. Implement any other feature of the Netflix application. For instance, develop the ability for users to like or dislike movies. A user can like or dislike a movie one time. Make sure to include details about these additional features in your report. - -4. Use a database in your program; You can choose between NoSQL databases like MongoDB and SQL databases like MySQL, PostgreSQL, etc. Get familiar with java database connectivity (JDBC). - -5. Add a simple GUI (Graphical User Interface) to your project. It's recommended to use JavaFX. This GUI should include all of the options offered by the command line menu you implemented earlier. Displaying pictures or icons is optional. - -## Submission -- Push your code to your fork on GitHub -- Upload your report to your fork on GitHub -- Create a pull request on the default branch of you own fork of the assignment on GitHub - -The deadline for submitting your code is Wednesday, March 15 (24th of Esfand). Any commit made after this date will not affect your score. - -Good luck and happy coding! +1.Input Validation +2.i used hash map for passwords and usernames +3.there are more than one way to search and find the movie you want \ No newline at end of file diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index 0718b5a..f8f00a5 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -1,14 +1,282 @@ package org.example; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Scanner; + public class Main { - //don't limit yourself to our template *** + static Scanner input = new Scanner(System.in); + static NetflixService netflixService = new NetflixService(); public static void main(String[] args) { + //---------------------------------------------------------movie templates------------------------------------------------------ + + Movie fiveFeetApart = new Movie("Five Feet Apart", "Romance", 2019, 116, 7.2, new ArrayList<>(Arrays.asList("Haley Lu Richardson", "Cole Sprouse", "Moises Arias")), 116); + Movie interstellar = new Movie("Interstellar", "Science Fiction", 2014, 169, 8.6, new ArrayList<>(Arrays.asList("Matthew McConaughey", "Anne Hathaway", "Jessica Chastain")), 169); + Movie wolfOfWallStreet = new Movie("The Wolf of Wall Street", "Comedy/Drama", 2013, 180, 8.2, new ArrayList<>(Arrays.asList("Leonardo DiCaprio", "Jonah Hill", "Margot Robbie")), 180); + + netflixService.addMovie(fiveFeetApart); + netflixService.addMovie(interstellar); + netflixService.addMovie(wolfOfWallStreet); + + + //---------------------------------------------------------TvShow templates------------------------------------------------------ + TVShow friends = new TVShow("Friends", "Sitcom", 1994, 236, 8.9, new ArrayList<>(Arrays.asList("Jennifer Aniston", "Courteney Cox", "Lisa Kudrow"))); + TVShow breakingBad = new TVShow("Breaking Bad", "Crime Drama", 2008, 62, 9.4, new ArrayList<>(Arrays.asList("Bryan Cranston", "Aaron Paul", "Anna Gunn"))); + + netflixService.addTVShow(friends); + netflixService.addTVShow(breakingBad); + + + //------------------------------------menu stuff---------------------------------- + netflixService.createAccount("farid","1234"); + netflixMenu(); + } + + public static void netflixMenu(){ + System.out.println("\nNetflix Menu"); + System.out.println("1.Create Account"); + System.out.println("2.Login"); + System.out.println("3.Logout"); + System.out.println("4.Search by Title"); + System.out.println("5.Search by Genre"); + System.out.println("6.Search by Release Year"); + System.out.println("7.Search by Release Year in favourites"); + System.out.println("8.Search by Title in favourites"); + System.out.println("9.Search by Genre in favourites"); + System.out.println("10.Get recommendations"); + System.out.println("11.Add to favourites"); + System.out.println("12.See your favourites"); + System.out.println("13.Exit"); + int choice = input.nextInt(); + input.nextLine(); + + switch (choice) { + case 1: + createAccount(); + netflixMenu(); + break; + case 2: + login(); + netflixMenu(); + break; + case 3: + logout(); + netflixMenu(); + break; + case 4: + searchByTitle(); + netflixMenu(); + break; + case 5: + searchByGenre(); + netflixMenu(); + break; + case 6: + searchByReleaseYear(); + netflixMenu(); + break; + case 7: + searchByTitleInFavourites(); + netflixMenu(); + break; + case 8: + searchByGenreInFavourites(); + netflixMenu(); + break; + case 9: + searchByReleaseYearInFavourites(); + netflixMenu(); + break; + case 10: + recommendations(); + netflixMenu(); + break; + case 11: + addToFavourites(); + netflixMenu(); + break; + case 12: + showFavourites(); + netflixMenu(); + break; + case 13: + System.out.println("Goodbye!"); + return; + default: + System.out.println("Invalid choice! Please try again."); + netflixMenu(); + } + } + public static void createAccount() { + System.out.println("Enter a username:"); + String username = input.nextLine(); + System.out.println("Enter a password:"); + String password = input.nextLine(); + User user = netflixService.createAccount(username, password); + if (user == null) { + System.out.println("Username is already taken."); + } else { + System.out.println("Account created successfully."); + } } + public static void login() { + if (netflixService.getCurrentUser() != null) { + System.out.println("You are already logged in as " + netflixService.getCurrentUser().getUserName() + "."); + return; + } - public static void runMenu(){ - //TODO: + System.out.println("Enter your username:"); + String username = input.nextLine(); + System.out.println("Enter your password:"); + String password = input.nextLine(); + + if (netflixService.login(username, password)) { + System.out.println("You logged in successfully."); + //some menu to watch or something + } else { + System.out.println("Wrong password or username!"); + login(); + } + } + public static void logout() { + if (netflixService.getCurrentUser() == null) { + System.out.println("You are not logged in."); + } else { + System.out.println("Goodbye, " + netflixService.getCurrentUser().getUserName() + "!"); + netflixService.logout(); + } + } + public static void searchByTitle() { + System.out.println("Enter a title:"); + String title = input.nextLine(); + ArrayList tvShow = netflixService.searchByTitle(title); + if (tvShow.size() == 0) { + System.out.println("No TV show or movie found with that title."); + } else { + for (TVShow show : tvShow) { + System.out.println("Title: " + show.getTitle()); + System.out.println("Genre: " + show.getGenre()); + System.out.println("Release Year: " + show.getReleaseYear()); + System.out.println("-----------------------"); + } + } + } + public static void searchByGenre(){ + System.out.println("Enter a genre:"); + String genre = input.nextLine(); + ArrayList tvShow = netflixService.searchByGenre(genre); + if (tvShow.size() == 0) { + System.out.println("No TV show or movie found with that genre."); + } + else { + for (TVShow show : tvShow) { + System.out.println("Title: " + show.getTitle()); + System.out.println("Genre: " + show.getGenre()); + System.out.println("Release Year: " + show.getReleaseYear()); + System.out.println("-----------------------"); + } + } + } + public static void searchByReleaseYear(){ + System.out.println("Enter a Year:"); + int year = input.nextInt(); + ArrayList tvShow = netflixService.searchByReleaseYear(year); + if (tvShow.size() == 0) { + System.out.println("No TV show or movie found in that year."); + } + else { + for (TVShow show : tvShow) { + System.out.println("Title: " + show.getTitle()); + System.out.println("Genre: " + show.getGenre()); + System.out.println("Release Year: " + show.getReleaseYear()); + System.out.println("-----------------------"); + } + } + } + public static void searchByTitleInFavourites() { + System.out.println("Enter a title:"); + String title = input.nextLine(); + ArrayList tvShow = netflixService.getCurrentUser().searchByTitle(title); + if (tvShow.size() == 0) { + System.out.println("No TV show or movie found with that title."); + } else { + for (TVShow show : tvShow) { + System.out.println("Title: " + show.getTitle()); + System.out.println("Genre: " + show.getGenre()); + System.out.println("Release Year: " + show.getReleaseYear()); + System.out.println("-----------------------"); + } + } + } + public static void searchByGenreInFavourites(){ + System.out.println("Enter a genre:"); + String genre = input.nextLine(); + ArrayList tvShow = netflixService.getCurrentUser().searchByGenre(genre); + if (tvShow.size() == 0) { + System.out.println("No TV show or movie found with that genre."); + } + else { + for (TVShow show : tvShow) { + System.out.println("Title: " + show.getTitle()); + System.out.println("Genre: " + show.getGenre()); + System.out.println("Release Year: " + show.getReleaseYear()); + System.out.println("-----------------------"); + } + } + } + public static void searchByReleaseYearInFavourites(){ + System.out.println("Enter a Year:"); + int year = input.nextInt(); + ArrayList tvShow = netflixService.getCurrentUser().searchByReleaseYear(year); + if (tvShow.size() == 0) { + System.out.println("No TV show or movie found in that year."); + } + else { + for (TVShow show : tvShow) { + System.out.println("Title: " + show.getTitle()); + System.out.println("Genre: " + show.getGenre()); + System.out.println("Release Year: " + show.getReleaseYear()); + System.out.println("-----------------------"); + } + } + } + public static void recommendations() { + ArrayList recommendationsList = netflixService.getCurrentUser().getRecommendations(netflixService); + System.out.println("Here are some Movies and Shows you might enjoy:"); + for(TVShow show : recommendationsList){ + System.out.println("Title: " + show.getTitle()); + System.out.println("Genre: " + show.getGenre()); + System.out.println("Release Year: " + show.getReleaseYear()); + System.out.println("-----------------------"); + } + } + public static void addToFavourites(){ + System.out.println("Enter a title"); + String title = input.nextLine(); + if(netflixService.getCurrentUser().getfavouriteShow().contains(netflixService.searchForTitle(title))){ + System.out.println("You have already added this movie to your favourites!"); + return; + } + if(netflixService.searchForTitle(title) != null) { + netflixService.getCurrentUser().addToFavorites(netflixService.searchForTitle(title)); + System.out.println("Movie has been added to the favourites."); + } + else{ + System.out.println("Movie not found!"); + } + } + public static void showFavourites(){ + System.out.println("These are your favourites Show and Movies:"); + ArrayList favourites = netflixService.getCurrentUser().getfavouriteShow(); + for(TVShow show : favourites){ + System.out.println("Title: " + show.getTitle()); + System.out.println("Genre: " + show.getGenre()); + System.out.println("Release Year: " + show.getReleaseYear()); + System.out.println("-----------------------"); + } } } + diff --git a/src/main/java/org/example/Movie.java b/src/main/java/org/example/Movie.java index 081ba70..19caf3e 100644 --- a/src/main/java/org/example/Movie.java +++ b/src/main/java/org/example/Movie.java @@ -3,11 +3,18 @@ import java.util.ArrayList; class Movie extends TVShow { - /* - *Movie is extended from TVShow and has extra attribute length. - */ - public Movie() - { - super(); + private int length; + + public Movie(String title, String genre, int releaseYear, int durationMinute, double rating, ArrayList castMember, int lengthMinute) { + super(title, genre, releaseYear, durationMinute, rating, castMember); + this.length = length; + } + + public int getLength() { + return length; + } + + public void setLength(int length) { + this.length = length; } -} +} \ No newline at end of file diff --git a/src/main/java/org/example/NetflixService.java b/src/main/java/org/example/NetflixService.java index 5345a3e..700ffb8 100644 --- a/src/main/java/org/example/NetflixService.java +++ b/src/main/java/org/example/NetflixService.java @@ -1,49 +1,133 @@ package org.example; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Objects; class NetflixService { - /* - *The NetflixService should have an Arraylist of users, tv shows and movies. - *The NetflixService should have a User object which represents current user. - */ + + private ArrayList movieList; + private ArrayList tvShowList; + private HashMap userList; + private User currentUser; + + public NetflixService() { + this.movieList = new ArrayList<>(); + this.tvShowList = new ArrayList<>(); + this.userList = new HashMap<>(); + this.currentUser = null; + } + + public ArrayList getMovieList() { + return movieList; + } + + public void setMovieList(ArrayList movieList) { + this.movieList = movieList; + } + + public ArrayList getTvShowList() { + return tvShowList; + } + public void setTvShowList(ArrayList tvShowList) { + this.tvShowList = tvShowList; + } + + public User getCurrentUser() { + return currentUser; + } + + public void setCurrentUser(User user) { + currentUser = user; + } + public void addTVShow(TVShow tvShow){ - // Implement add tv show logic here + tvShowList.add(tvShow); } public void addMovie(Movie movie){ - // Implement add movie logic here + movieList.add(movie); } - public void createAccount(String username, String password) { - // Implement create account logic here + public User createAccount(String username, String password) { + if(!userList.containsKey(username)) { + User user = new User(username , password); + userList.put(username , user); + return user; + } + return null; } public boolean login(String username, String password) { - // Implement login logic here - return false; + if(userList.containsKey(username) && Objects.equals(userList.get(username).getpassword(), password)){ + currentUser = userList.get(username); + return true; + } + else{ + return false; + } } public void logout() { - // Implement logout logic here + currentUser = null; } - public ArrayList searchByTitle(String title) { - // Implement search by title logic here - return null; + public ArrayList searchByTitle(String title){ + ArrayList list = new ArrayList<>(); + for(TVShow show : tvShowList){ + if(show.getTitle().contains(title)){ + list.add(show); + } + } + for(TVShow show : movieList){ + if(show.getTitle().contains(title)){ + list.add(show); + } + } + return list; } - - public ArrayList searchByGenre(String genre) { - // Implement search by genre logic here + public TVShow searchForTitle(String title){ + for(TVShow show : tvShowList){ + if(title.equals(show.getTitle())){ + return show; + } + } + for(TVShow show : movieList){ + if(title.equals(show.getTitle())){ + return show; + } + } return null; } - + public ArrayList searchByGenre(String genre){ + ArrayList list = new ArrayList<>(); + for(TVShow show : tvShowList){ + if(show.getGenre().contains(genre)){ + list.add(show); + } + } + for(TVShow show : movieList){ + if(show.getGenre().contains(genre)){ + list.add(show); + } + } + return list; + } public ArrayList searchByReleaseYear(int year) { - // Implement search by release year logic here - return null; + ArrayList list = new ArrayList<>(); + for(TVShow show : tvShowList){ + if(show.getReleaseYear() == year){ + list.add(show); + } + } + for(TVShow show : movieList){ + if(show.getReleaseYear() == year){ + list.add(show); + } + } + return list; } } - diff --git a/src/main/java/org/example/TVShow.java b/src/main/java/org/example/TVShow.java index 005c218..3376b8a 100644 --- a/src/main/java/org/example/TVShow.java +++ b/src/main/java/org/example/TVShow.java @@ -7,5 +7,68 @@ class TVShow { *The TVShow should have a title , genre, release year, duration and a rating. *The TVShow should have an ArrayList of the cast. */ + private String title; + private String genre; + private int releaseYear; + private int duration; + private double rating; + private ArrayList cast; + TVShow(String title, String genre, int releaseYear, int duration, double rating, ArrayList cast){ + this.cast = cast; + this.duration = duration; + this.rating = rating; + this.genre = genre; + this.releaseYear = releaseYear; + this.title = title; + } + public void setTitle(String title) { + this.title = title; + } + + public void setGenre(String genre) { + this.genre = genre; + } + + public void setReleaseYear(int releaseYear) { + this.releaseYear = releaseYear; + } + + public void setDurationMinute(int duration) { + this.duration = duration; + } + + public void setRating(double rating) { + this.rating = rating; + } + + public void setCast(ArrayList cast) { + this.cast = cast; + } + public String getTitle() { + return title; + } + + public String getGenre() { + return genre; + } + + public int getReleaseYear() { + return releaseYear; + } + + public int getDuration() { + return duration; + } + + public double getRating() { + return rating; + } + + public ArrayList getCast() { + return cast; + } + public void addCast(String name){ + cast.add(name); + } } diff --git a/src/main/java/org/example/User.java b/src/main/java/org/example/User.java index 538e12b..98ccb1b 100644 --- a/src/main/java/org/example/User.java +++ b/src/main/java/org/example/User.java @@ -1,36 +1,94 @@ package org.example; import java.util.ArrayList; +import java.util.Scanner; class User { /* * The user should contain username password. * The user should contain an ArrayList of favorite shows and watch history. - * FUNCTION: the user should have a function to watch a show and add it to watch history. - * *** NOTE: All search functions in user are for searching in favorite shows *** */ + private String userName; + private String password; + private ArrayList favouriteShow; + public User (String userName, String password){ + this.userName = userName; + this.password = password; + this.favouriteShow = new ArrayList<>(); + } - public ArrayList searchByTitle(String title) { - // Implement search by title in favorite shows logic here - return null; + public String getUserName(){ + return userName; + } + public void setUserName(String username){ + this.userName = userName; + } + public String getpassword(){ + return password; + } + public void setpassword(String password){ + this.password = password; } - public ArrayList searchByGenre(String genre) { - // Implement search by genre in favorite shows logic here - return null; + public ArrayList getfavouriteShow(){ + return favouriteShow; + } + public void setFavouriteShow(ArrayList favouriteshow){ + this.favouriteShow = favouriteShow; + } + + +//...........................METHODS....................................................... + + + public ArrayList searchByTitle(String title){ + ArrayList save = new ArrayList<>(); + for (int i=0; i searchByGenre(String genre){ + ArrayList list = new ArrayList<>(); + for(TVShow show : favouriteShow){ + if(show.getGenre().contains(genre)){ + list.add(show); + } + } + return list; } public ArrayList searchByReleaseYear(int year) { - // Implement search by release year in favorite shows logic here - return null; + ArrayList list = new ArrayList<>(); + for(TVShow show : favouriteShow){ + if(show.getReleaseYear() == year){ + list.add(show); + } + } + return list; } public void addToFavorites(TVShow show) { - // Implement add to favorites logic here - } - public void viewFavorites() { - // Implement view favorites logic here + favouriteShow.add(show); } - public ArrayList getRecommendations() { - // Implement get recommendations logic here - return null; + public ArrayList getRecommendations(NetflixService netflix) { + ArrayList recommendations = new ArrayList<>(); + for (TVShow tvShow : netflix.getTvShowList()) { + //Check if the TV show has not been already watched + if (!favouriteShow.contains(tvShow)) { + //Check if the TV show has the same genre as the last watched TV show by the user + if (favouriteShow.size() > 0 && (tvShow.getGenre().contains(favouriteShow.get(favouriteShow.size() - 1).getGenre()) || favouriteShow.get(favouriteShow.size() - 1).getGenre().contains(tvShow.getGenre()))) { + recommendations.add(tvShow); + } + //Check if the TV show has a high rating + else if (tvShow.getRating() > 8.0) { + recommendations.add(tvShow); + } + } + } + return recommendations; + } -} +} \ No newline at end of file