diff --git a/src/main/Fourth Assignment Report.pdf b/src/main/Fourth Assignment Report.pdf new file mode 100644 index 0000000..6a24c1e Binary files /dev/null and b/src/main/Fourth Assignment Report.pdf differ diff --git a/src/main/UML.drawio.pdf b/src/main/UML.drawio.pdf new file mode 100644 index 0000000..50abfe8 Binary files /dev/null and b/src/main/UML.drawio.pdf differ diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index 0718b5a..7790e78 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -1,14 +1,150 @@ package org.example; - +import java.util.ArrayList; +import java.util.Scanner; public class Main { - //don't limit yourself to our template *** + public static void main(String[] args) { + NetflixService netflix = new NetflixService(); + Scanner scanner = new Scanner(System.in); + while (true) { + System.out.println("1. Add TV Show"); + System.out.println("2. Add Movie"); + System.out.println("3. Create Account"); + System.out.println("4. Login"); + System.out.println("5. Logout"); + System.out.println("6. Search TV Shows by Title"); + System.out.println("7. Search TV Shows by Genre"); + System.out.println("8. Search TV Shows by Release Year"); + System.out.println("9. Exit"); - public static void main(String[] args) { + System.out.print("Enter choice: "); + int choice = scanner.nextInt(); + switch (choice) { + case 1: + System.out.print("Enter TV show title: "); + String tvShowTitle = scanner.next(); + System.out.print("Enter TV show genre: "); + String tvShowGenre = scanner.next(); + System.out.print("Enter TV show release year: "); + int tvShowReleaseYear = scanner.nextInt(); + System.out.print("Enter TV show number of episodes: "); + int tvShowNumEpisodes = scanner.nextInt(); + TVShow tvShow = new TVShow(tvShowTitle, tvShowGenre, tvShowReleaseYear, tvShowNumEpisodes); + netflix.addTVShow(tvShow); + System.out.println("TV show added successfully."); + break; + case 2: + System.out.print("Enter movie title: "); + String movieTitle = scanner.next(); + System.out.print("Enter movie genre: "); + String movieGenre = scanner.next(); + System.out.print("Enter movie release year: "); + int movieReleaseYear = scanner.nextInt(); + System.out.print("Enter movie number of episodes: "); + int movieNumEpisodes = scanner.nextInt(); + System.out.print("Enter movie duration: "); + int movieDuration = scanner.nextInt(); + Movie movie = new Movie(movieTitle, movieGenre, movieReleaseYear, movieNumEpisodes, movieDuration); + netflix.addMovie(movie); + System.out.println("Movie added successfully."); + break; + case 3: + System.out.print("Enter username: "); + String username = scanner.next(); + System.out.print("Enter password: "); + String password = scanner.next(); + netflix.createAccount(username, password); + System.out.println("Account created successfully."); + break; + case 4: + System.out.print("Enter username: "); + String loginUsername = scanner.next(); + System.out.print("Enter password: "); + String loginPassword = scanner.next(); + boolean loginSuccess = netflix.login(loginUsername, loginPassword); + if (loginSuccess) { + System.out.println("Login successful."); + } else { + System.out.println("Login failed."); + } + break; + case 5: + netflix.logout(); + System.out.println("Logout successful."); + break; + case 6: + System.out.print("Enter TV show title: "); + String searchTitle = scanner.next(); + ArrayList searchTitleResults = netflix.searchByTitle(searchTitle); + for (TVShow result : searchTitleResults) { + System.out.println(result.getTitle() + " (" + result.getReleaseYear() + ")"); + } + break; + } + } } - public static void runMenu(){ - //TODO: + + public static void runMenu () { + Scanner scanner = new Scanner(System.in); + while (true) { + System.out.println(); + System.out.println("Main Menu"); + System.out.println("1. Login"); + System.out.println("2. Create Account"); + System.out.println("3. Search TV Shows by Title"); + System.out.println("4. Search TV Shows by Genre"); + System.out.println("5. Search TV Shows by Release Year"); + System.out.println("6. View Favorites"); + System.out.println("7. Get Recommendations"); + System.out.println("8. Logout"); + System.out.println("9. Quit"); + + System.out.print("Enter a choice: "); + int choice = scanner.nextInt(); + + switch (choice) { + case 1: + System.out.print("Enter username: "); + String username = scanner.next(); + System.out.print("Enter password: "); + String password = scanner.next(); + if (NetflixService.login(username, password)) { + User currentUser = NetflixService.getCurrentUser(); + System.out.println("Login successful"); + } else { + System.out.println("Invalid username or password"); + } + break; + case 2: + System.out.print("Enter username: "); + String newUsername = scanner.next(); + System.out.print("Enter password: "); + String newPassword = scanner.next(); + NetflixService.createAccount(newUsername, newPassword); + System.out.println("Account created successfully"); + break; + case 3: + System.out.print("Enter a title: "); + String title = scanner.next(); + ArrayList resultsByTitle = NetflixService.searchByTitle(title); + System.out.println("Results:"); + for (TVShow tvShow : resultsByTitle) { + System.out.println(tvShow.getTitle() + " (" + tvShow.getReleaseYear() + ")"); + } + break; + case 4: + System.out.print("Enter a genre: "); + String genre = scanner.next(); + ArrayList resultsByGenre = NetflixService.searchByGenre(genre); + System.out.println("Results:"); + for (TVShow tvShow : resultsByGenre) { + System.out.println(tvShow.getTitle() + " (" + tvShow.getReleaseYear() + ")"); + } + break; + + } + } } -} +} \ No newline at end of file diff --git a/src/main/java/org/example/Movie.java b/src/main/java/org/example/Movie.java index 081ba70..ba16622 100644 --- a/src/main/java/org/example/Movie.java +++ b/src/main/java/org/example/Movie.java @@ -1,13 +1,14 @@ package org.example; -import java.util.ArrayList; - class Movie extends TVShow { - /* - *Movie is extended from TVShow and has extra attribute length. - */ - public Movie() - { - super(); + private int duration; + + public Movie(String title, String genre, int releaseYear, int numEpisodes, int duration) { + super(title, genre, releaseYear, numEpisodes); + this.duration = duration; + } + + public int getDuration() { + return duration; } } diff --git a/src/main/java/org/example/NetflixService.java b/src/main/java/org/example/NetflixService.java index 5345a3e..5d0df26 100644 --- a/src/main/java/org/example/NetflixService.java +++ b/src/main/java/org/example/NetflixService.java @@ -1,49 +1,84 @@ package org.example; - import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; 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 List movies; + private static List tvShows; + private static List users; + private static User currentUser; + + public NetflixService() { + movies = new ArrayList<>(); + tvShows = new ArrayList<>(); + users = new ArrayList<>(); + currentUser = null; + } public void addTVShow(TVShow tvShow){ - // Implement add tv show logic here + Movie movie = null; + movies.add(movie); } public void addMovie(Movie movie){ - // Implement add movie logic here + TVShow tvShow = null; + tvShows.add(tvShow); } - public void createAccount(String username, String password) { - // Implement create account logic here + public static void createAccount(String username, String password) { + User user = new User(username, password); + users.add(user); } - public boolean login(String username, String password) { - // Implement login logic here + public static boolean login(String username, String password) { + for (User user : users) { + if (user.getUsername().equals(username) && user.getPassword().equals(password)) { + currentUser = user; + return true; + } + } 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 static ArrayList searchByTitle(String title) { + List results = new ArrayList<>(); + for (TVShow tvShow : tvShows) { + if (tvShow.getTitle().toLowerCase().contains(title.toLowerCase())) { + results.add(tvShow); + } + } + return (ArrayList) results; } - public ArrayList searchByGenre(String genre) { - // Implement search by genre logic here - return null; + public static ArrayList searchByGenre(String genre) { + List results = new ArrayList<>(); + for (TVShow tvShow : tvShows) { + if (tvShow.getGenre().toLowerCase().equals(genre.toLowerCase())) { + results.add(tvShow); + } + } + return (ArrayList) results; } + public ArrayList searchByReleaseYear(int year) { - // Implement search by release year logic here - return null; - } + List results = new ArrayList<>(); + for (TVShow tvShow : tvShows) { + if (tvShow.getReleaseYear() == year) { + results.add(tvShow); + } + } + return (ArrayList) results; + } + public static User getCurrentUser() { + return currentUser; + } } diff --git a/src/main/java/org/example/TVShow.java b/src/main/java/org/example/TVShow.java index 005c218..7b57c2e 100644 --- a/src/main/java/org/example/TVShow.java +++ b/src/main/java/org/example/TVShow.java @@ -1,11 +1,61 @@ package org.example; +import java.nio.charset.Charset; import java.util.ArrayList; - +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.List; 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 numEpisodes; + private Collection similarTVShows; + private Movie[] movies; + + public TVShow(String title, String genre, int releaseYear, int numEpisodes) { + this.title = title; + this.genre = genre; + this.releaseYear = releaseYear; + this.numEpisodes = numEpisodes; + } + + public String getTitle() { + return title; + } + + public String getGenre() { + return genre; + } + + public int getReleaseYear() { + return releaseYear; + } + + public int getNumEpisodes() { + return numEpisodes; + } + + public void setSimilarTVShows(Collection similarTVShows) { + this.similarTVShows = similarTVShows; + } + + + public List getGenres() { + Set genres = new HashSet<>(); + Iterable tvShows = null; + for (TVShow tvShow : tvShows) { + genres.add(tvShow.getGenre()); + } + for (Movie movie : movies) { + genres.add(movie.getGenre()); + } + return new ArrayList<>(genres); + } + + public Collection getSimilarTVShows() { + return similarTVShows; + } } diff --git a/src/main/java/org/example/User.java b/src/main/java/org/example/User.java index 538e12b..e861dae 100644 --- a/src/main/java/org/example/User.java +++ b/src/main/java/org/example/User.java @@ -1,36 +1,81 @@ package org.example; - import java.util.ArrayList; +import java.util.List; 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 List favoriteTVShows; + private List watchedTVShows; + public User(String username, String password) { + this.username = username; + this.password = password; + this.favoriteTVShows = new ArrayList<>(); + this.watchedTVShows = new ArrayList<>(); + } - public ArrayList searchByTitle(String title) { - // Implement search by title in favorite shows logic here - return null; + public String getUsername() { + return username; } - public ArrayList searchByGenre(String genre) { - // Implement search by genre in favorite shows logic here - return null; + + public String getPassword() { + return password; } - public ArrayList searchByReleaseYear(int year) { - // Implement search by release year in favorite shows logic here - return null; + + public void watchTVShow(TVShow tvShow) { + watchedTVShows.add(tvShow); + System.out.println(username + " is watching " + tvShow.getTitle()); } - public void addToFavorites(TVShow show) { - // Implement add to favorites logic here + + public void addToFavorites(TVShow tvShow) { + favoriteTVShows.add(tvShow); + System.out.println(tvShow.getTitle() + " added to favorites for " + username); } + public void viewFavorites() { - // Implement view favorites logic here + System.out.println(username + "'s favorite TV shows:"); + for (TVShow tvShow : favoriteTVShows) { + System.out.println(tvShow.getTitle()); + } + } + + public List getRecommendations() { + List recommendations = new ArrayList<>(); + for (TVShow tvShow : favoriteTVShows) { + recommendations.addAll(tvShow.getSimilarTVShows()); + } + return recommendations; + } + + public List searchByTitle(String query) { + List searchResults = new ArrayList<>(); + for (TVShow tvShow : favoriteTVShows) { + if (tvShow.getTitle().contains(query)) { + searchResults.add(tvShow); + } + } + return searchResults; } - public ArrayList getRecommendations() { - // Implement get recommendations logic here - return null; + + public List searchByGenre(String query) { + List searchResults = new ArrayList<>(); + for (TVShow tvShow : favoriteTVShows) { + if (tvShow.getGenres().contains(query)) { + searchResults.add(tvShow); + } + } + return searchResults; + } + + + public List searchByReleaseYear(int year) { + List searchResults = new ArrayList<>(); + for (TVShow tvShow : favoriteTVShows) { + if (tvShow.getReleaseYear() == year) { + searchResults.add(tvShow); + } + } + return searchResults; } }