diff --git a/build.gradle b/build.gradle index 3cae2d7..2cf926e 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,9 @@ repositories { dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' + // https://mvnrepository.com/artifact/org.json/json + implementation group: 'org.json', name: 'json', version: '20230227' + } test { diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index 0718b5a..643b2d0 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -1,14 +1,138 @@ package org.example; +import java.util.ArrayList; +import java.util.Scanner; public class Main { //don't limit yourself to our template *** + private static NetflixService netflixService = new NetflixService(); + private static User currentUser = null; + private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { + // Creating some sample users + netflixService.createAccount("user1", "password1"); + netflixService.createAccount("user2", "password2"); + runMenu(); } public static void runMenu(){ //TODO: + int choice = 0; + while (choice == 0) + { + System.out.println("Netflix Menu:"); + System.out.println("1. Create Account"); + System.out.println("2. Login"); + System.out.println("3. Logout"); + System.out.println("4. Search TV Shows by Title"); + System.out.println("5. Search TV Shows by Genre"); + System.out.println("6. Search TV Shows by Release Year"); + System.out.println("7. Add TV Show"); + System.out.println("8. Add Movie"); + System.out.println("9. Exit"); + System.out.print("Enter your choice: "); + choice = scanner.nextInt(); + scanner.nextLine(); // Consume the leftover newline character + + switch (choice) { + case 1: + System.out.print("Enter username: "); + String username = scanner.nextLine(); + System.out.print("Enter password: "); + String password = scanner.nextLine(); + netflixService.createAccount(username, password); + break; + case 2: + System.out.print("Enter username: "); + String loginUsername = scanner.nextLine(); + System.out.print("Enter password: "); + String loginPassword = scanner.nextLine(); + boolean loginSuccess = netflixService.login(loginUsername, loginPassword); + if (loginSuccess) { + currentUser = netflixService.getUser(); + System.out.println("Welcome, " + currentUser.getUsername() + "!"); + } else { + System.out.println("Invalid username or password."); + } + break; + case 3: + if (currentUser != null) { + netflixService.logout(); + currentUser = null; + System.out.println("Logged out successfully."); + } else { + System.out.println("You are not logged in."); + } + break; + case 4: + System.out.print("Enter title: "); + String title = scanner.nextLine(); + netflixService.searchByTitle(title); + break; + case 5: + System.out.print("Enter genre: "); + String genre = scanner.nextLine(); + netflixService.searchByGenre(genre); + break; + case 6: + System.out.print("Enter release year: "); + int year = scanner.nextInt(); + netflixService.searchByReleaseYear(year); + break; + case 7: + if (currentUser != null) { + System.out.print("Enter title: "); + String tvShowTitle = scanner.nextLine(); + System.out.print("Enter genre: "); + String tvShowGenre = scanner.nextLine(); + System.out.print("Enter release year: "); + int tvShowYear = scanner.nextInt(); + scanner.nextLine(); // Consume the leftover newline character + System.out.print("Enter duration: "); + String tvShowDuration = scanner.nextLine(); + System.out.print("Enter rating: "); + String tvShowRating = scanner.nextLine(); + /*System.out.print("Enter cast (separated by commas): "); + String castString = scanner.nextLine(); + String[] castArray = castString.split(",");*/ + ArrayList cast = null; + netflixService.addTVShow(new TVShow(tvShowTitle, tvShowGenre, tvShowYear, tvShowDuration, tvShowRating, cast)); + TVShow tvShow = null; + netflixService.addTVShow(tvShow); + System.out.println("TV show added successfully."); + } + + case 8: + if (currentUser != null) { + System.out.println("Logging out..."); + netflixService.logout(); + currentUser = null; + } else { + System.out.println("You are not logged in!"); + } + break; + + case 9: + if (currentUser != null) { + System.out.println("You are already logged in!"); + } else { + System.out.print("Enter your username: "); + username = scanner.next(); + System.out.print("Enter your password: "); + password = scanner.next(); + + if (netflixService.login(username, password)) { + System.out.println("Login successful!"); + currentUser = netflixService.getUser(); + } else { + System.out.println("Invalid username or password!"); + } + } + break; + + } + } } } diff --git a/src/main/java/org/example/Movie.java b/src/main/java/org/example/Movie.java index 081ba70..1d48412 100644 --- a/src/main/java/org/example/Movie.java +++ b/src/main/java/org/example/Movie.java @@ -6,8 +6,22 @@ class Movie extends TVShow { /* *Movie is extended from TVShow and has extra attribute length. */ - public Movie() + private final ArrayList length; + public Movie(String title, String genre, int releaseYear, String duration, String rating, ArrayList cast, ArrayList length) { - super(); + super(title, genre, releaseYear, duration, rating, cast); + this.length = length; + } + + public ArrayList getLength() { + return length; + } + + @Override + public String toString() { + return "Movie{title=" + getTitle() + " genre="+getGenre()+ " releaseYear=" + getReleaseYear()+ + " duration="+getDuration()+" rating="+getRating()+ + " cast="+getCast() + " length=" + getLength() + '}'; } } + diff --git a/src/main/java/org/example/NetflixService.java b/src/main/java/org/example/NetflixService.java index 5345a3e..a9d4358 100644 --- a/src/main/java/org/example/NetflixService.java +++ b/src/main/java/org/example/NetflixService.java @@ -7,43 +7,103 @@ 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. */ + ArrayList userList; + ArrayList tvShowList; + ArrayList movieList; + private User user; + + public NetflixService(){ + this.userList = new ArrayList<>(); + this.tvShowList = new ArrayList<>(); + this.movieList= new ArrayList<>(); + } + + public void addUser(User user) { + userList.add(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 + User user = new User(username, password); + addUser(user); } public boolean login(String username, String password) { // Implement login logic here + for (User user : userList) { + if (user.getUsername().equals(username) && user.getPassword().equals(password)) { + this.user = user; + return true; + } + } return false; } public void logout() { // Implement logout logic here + user = null; } public ArrayList searchByTitle(String title) { // Implement search by title logic here - return null; + ArrayList result = new ArrayList<>(); + for (TVShow tvShow : tvShowList) { + if (tvShow.getTitle().equals(title)) { + result.add(tvShow); + } + } + return result; } public ArrayList searchByGenre(String genre) { // Implement search by genre logic here - return null; + ArrayList result = new ArrayList<>(); + for (TVShow tvShow : tvShowList) { + if (tvShow.getGenre().equals(genre)) { + result.add(tvShow); + } + } + return result; } public ArrayList searchByReleaseYear(int year) { // Implement search by release year logic here - return null; + ArrayList result = new ArrayList<>(); + for (TVShow tvShow : tvShowList) { + if (tvShow.getReleaseYear() == year) { + result.add(tvShow); + } + } + return result; + } + public ArrayList searchMoviesByLength(ArrayList length) { + ArrayList result = new ArrayList<>(); + for (Movie movie : movieList) { + if (movie.getLength() == length) { + result.add(movie); + } + } + return result; + } + + public User getUser() { + return user; } + public void setUser(User user) { + this.user = user; + } } diff --git a/src/main/java/org/example/TVShow.java b/src/main/java/org/example/TVShow.java index 005c218..344f21b 100644 --- a/src/main/java/org/example/TVShow.java +++ b/src/main/java/org/example/TVShow.java @@ -1,6 +1,7 @@ package org.example; import java.util.ArrayList; +import java.util.Scanner; class TVShow { /* @@ -8,4 +9,91 @@ class TVShow { *The TVShow should have an ArrayList of the cast. */ + private String title; + private String genre; + private int releaseYear; + private String duration; + private String rating; + ArrayList cast; + + public TVShow(String title , String genre ,int releaseYear , String duration , String rating , ArrayList cast) + { + this.title = title; + this.genre = genre; + this.releaseYear = releaseYear; + this.duration = duration; + this.rating = rating; + this.cast = cast; + } + + public TVShow() { + this.title = ""; + this.genre = ""; + this.releaseYear = 0; + this.duration = ""; + this.rating = ""; + this.cast = new ArrayList<>(); + } + + + public String getTitle() { + return title; + } + + public String getGenre() { + return genre; + } + + public int getReleaseYear() { + return releaseYear; + } + + public String getDuration() { + return duration; + } + + public String getRating() { + return rating; + } + + public ArrayList getCast() { + return cast; + } + + 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 setDuration(String duration) { + this.duration = duration; + } + + public void setRating(String rating) { + this.rating = rating; + } + + public void setCast(ArrayList cast) { + this.cast = cast; + } + + @Override + public String toString() { + return "TVShow{" + + "title='" + title + '\'' + + ", genre='" + genre + '\'' + + ", releaseYear=" + releaseYear + + ", duration='" + duration + '\'' + + ", rating='" + rating + '\'' + + ", cast=" + cast + + '}'; + } + } diff --git a/src/main/java/org/example/User.java b/src/main/java/org/example/User.java index 538e12b..66de039 100644 --- a/src/main/java/org/example/User.java +++ b/src/main/java/org/example/User.java @@ -10,27 +10,181 @@ class User { * *** NOTE: All search functions in user are for searching in favorite shows *** */ + private String username; + private String password; + ArrayList userList; + ArrayList favoriteShowList ; + ArrayList watchHistoryList ; + + public User(String username , String password){ + this.username =username; + this.password =password; + this.favoriteShowList = new ArrayList<>(); + this.watchHistoryList = new ArrayList<>(); + this.userList = new ArrayList<>(); + } + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public void setUsername(String username) { + this.username = username; + } + + public void setPassword(String password) { + this.password = password; + } + + public void watchShow(TVShow tvShow){ + watchHistoryList.add(tvShow); + } + + public ArrayList getWatchHistoryList() { + return watchHistoryList; + } + + public void setWatchHistoryList(ArrayList watchHistoryList) { + this.watchHistoryList = watchHistoryList; + } + public ArrayList searchByTitle(String title) { // Implement search by title in favorite shows logic here - return null; + ArrayList result = new ArrayList<>(); + for (TVShow tvShow : favoriteShowList) + { + if(title.compareTo(tvShow.getTitle())== 0) + { + result.add(tvShow); + } + } + return result; } public ArrayList searchByGenre(String genre) { // Implement search by genre in favorite shows logic here - return null; + ArrayList result = new ArrayList<>(); + for (TVShow tvShow : favoriteShowList) + { + if(genre.compareTo(tvShow.getGenre())== 0) + { + result.add(tvShow); + } + } + return result; } public ArrayList searchByReleaseYear(int year) { // Implement search by release year in favorite shows logic here - return null; + ArrayList result = new ArrayList<>(); + for (TVShow tvShow : favoriteShowList) + { //cause this is int and can't use compare method + if(year == tvShow.getReleaseYear()) + { + result.add(tvShow); + } + } + return result; } public void addToFavorites(TVShow show) { // Implement add to favorites logic here + favoriteShowList.add(show); + System.out.println("ADD SUCCESSFULLY"); + } + + public ArrayList getFavoriteShowList() { + return favoriteShowList; + } + + public void setFavoriteShowList(ArrayList favoriteShowList) { + + this.favoriteShowList = favoriteShowList; } public void viewFavorites() { // Implement view favorites logic here + System.out.print("Your favorites are :\n" + favoriteShowList); } - public ArrayList getRecommendations() { + + /*public ArrayList getRecommendations() { // Implement get recommendations logic here - return null; + /*System.out.println(" Suggested Movie "); + if(getGenre().equals("Mystery")){ + System.out.print("The Woman In the Window\nMurder Mystery\nKnives out\n"); + } + if(genre.equals("Psychology/Fiction")){ + System.out.print("Seven\nFight Club\nBlack Swan\n"); + } + System.out.println(" Suggested TV Show "); + if(genre.equals("Mystery")){ + System.out.print("Sharp Objects\nDefending Jacob\nThe Undoing\n"); + } + if(genre.equals("Psychology/Fiction")){ + System.out.print("Lost\nDark\nStranger Things\n"); + } + return null;*/ + /*private NetflixService netflixService = new NetflixService(); + private User currentUser = null; + + ArrayList recommendedShows = new ArrayList<>(); + + if (currentUser != null) { + // Get the user's watch history + ArrayList watchHistory = currentUser.getWatchHistoryList(); + + // Get all TV shows from the Netflix service + ArrayList allShows = netflixService.getTvShows(); + + // For each show in the user's watch history, add all shows in the same genre to the recommended list + for (TVShow watchedShow : watchHistory) { + String genre = watchedShow.getGenre(); + for (TVShow show : allShows) { + if (show.getGenre().equals(genre) && !watchHistory.contains(show) && !recommendedShows.contains(show)) { + recommendedShows.add(show); + } + } + } + + // If there are no shows recommended based on genre, add the top-rated shows + if (recommendedShows.isEmpty()) { + for (TVShow show : allShows) { + if (!watchHistory.contains(show) && show.getRating().equals("5")) { + recommendedShows.add(show); + } + } + } + } + + return recommendedShows; + } + + }*/ + + public void addHistory(TVShow tvShow){ + watchHistoryList.add(tvShow); + } + public void addFavorit(TVShow tvShow){ + favoriteShowList.add(tvShow); + } + public void addHistory(Movie movie){ + watchHistoryList.add(movie); } + public void addFavorit(Movie movie){ + favoriteShowList.add(movie); + } + + + + @Override + public String toString() { + return "User{" + + "username='" + username + '\'' + + ", password='" + password + '\'' + + ", favoriteShowList=" + favoriteShowList + + ", watchHistoryList=" + watchHistoryList + + ", userList=" + userList + + '}'; + } + }