Skip to content
Open
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
Binary file added src/main/Fourth Assignment Report.pdf
Binary file not shown.
Binary file added src/main/UML.drawio.pdf
Binary file not shown.
148 changes: 142 additions & 6 deletions src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -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<TVShow> 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<TVShow> 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<TVShow> resultsByGenre = NetflixService.searchByGenre(genre);
System.out.println("Results:");
for (TVShow tvShow : resultsByGenre) {
System.out.println(tvShow.getTitle() + " (" + tvShow.getReleaseYear() + ")");
}
break;

}
}
}
}
}
17 changes: 9 additions & 8 deletions src/main/java/org/example/Movie.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
77 changes: 56 additions & 21 deletions src/main/java/org/example/NetflixService.java
Original file line number Diff line number Diff line change
@@ -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<Movie> movies;
private static List<TVShow> tvShows;
private static List<User> 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<TVShow> searchByTitle(String title) {
// Implement search by title logic here
return null;
public static ArrayList<TVShow> searchByTitle(String title) {
List<TVShow> results = new ArrayList<>();
for (TVShow tvShow : tvShows) {
if (tvShow.getTitle().toLowerCase().contains(title.toLowerCase())) {
results.add(tvShow);
}
}
return (ArrayList<TVShow>) results;
}

public ArrayList<TVShow> searchByGenre(String genre) {
// Implement search by genre logic here
return null;
public static ArrayList<TVShow> searchByGenre(String genre) {
List<TVShow> results = new ArrayList<>();
for (TVShow tvShow : tvShows) {
if (tvShow.getGenre().toLowerCase().equals(genre.toLowerCase())) {
results.add(tvShow);
}
}
return (ArrayList<TVShow>) results;
}


public ArrayList<TVShow> searchByReleaseYear(int year) {
// Implement search by release year logic here
return null;
}
List<TVShow> results = new ArrayList<>();
for (TVShow tvShow : tvShows) {
if (tvShow.getReleaseYear() == year) {
results.add(tvShow);
}
}
return (ArrayList<TVShow>) results;

}

public static User getCurrentUser() {
return currentUser;
}
}

60 changes: 55 additions & 5 deletions src/main/java/org/example/TVShow.java
Original file line number Diff line number Diff line change
@@ -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<? extends TVShow> 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<? extends TVShow> similarTVShows) {
this.similarTVShows = similarTVShows;
}


public List<String> getGenres() {
Set<String> genres = new HashSet<>();
Iterable<? extends TVShow> tvShows = null;
for (TVShow tvShow : tvShows) {
genres.add(tvShow.getGenre());
}
for (Movie movie : movies) {
genres.add(movie.getGenre());
}
return new ArrayList<>(genres);
}

public Collection<? extends TVShow> getSimilarTVShows() {
return similarTVShows;
}
}
Loading