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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
124 changes: 124 additions & 0 deletions src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -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<String> 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;

}
}
}
}
18 changes: 16 additions & 2 deletions src/main/java/org/example/Movie.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,22 @@ class Movie extends TVShow {
/*
*Movie is extended from TVShow and has extra attribute length.
*/
public Movie()
private final ArrayList<String> length;
public Movie(String title, String genre, int releaseYear, String duration, String rating, ArrayList<String> cast, ArrayList<String> length)
{
super();
super(title, genre, releaseYear, duration, rating, cast);
this.length = length;
}

public ArrayList<String> getLength() {
return length;
}

@Override
public String toString() {
return "Movie{title=" + getTitle() + " genre="+getGenre()+ " releaseYear=" + getReleaseYear()+
" duration="+getDuration()+" rating="+getRating()+
" cast="+getCast() + " length=" + getLength() + '}';
}
}

66 changes: 63 additions & 3 deletions src/main/java/org/example/NetflixService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<User> userList;
ArrayList<TVShow> tvShowList;
ArrayList<Movie> 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<TVShow> searchByTitle(String title) {
// Implement search by title logic here
return null;
ArrayList<TVShow> result = new ArrayList<>();
for (TVShow tvShow : tvShowList) {
if (tvShow.getTitle().equals(title)) {
result.add(tvShow);
}
}
return result;
}

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

public ArrayList<TVShow> searchByReleaseYear(int year) {
// Implement search by release year logic here
return null;
ArrayList<TVShow> result = new ArrayList<>();
for (TVShow tvShow : tvShowList) {
if (tvShow.getReleaseYear() == year) {
result.add(tvShow);
}
}
return result;
}
public ArrayList<Movie> searchMoviesByLength(ArrayList length) {
ArrayList<Movie> 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;
}

}

88 changes: 88 additions & 0 deletions src/main/java/org/example/TVShow.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,99 @@
package org.example;

import java.util.ArrayList;
import java.util.Scanner;

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 String duration;
private String rating;
ArrayList<String> cast;

public TVShow(String title , String genre ,int releaseYear , String duration , String rating , ArrayList<String> 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<String> 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<String> cast) {
this.cast = cast;
}

@Override
public String toString() {
return "TVShow{" +
"title='" + title + '\'' +
", genre='" + genre + '\'' +
", releaseYear=" + releaseYear +
", duration='" + duration + '\'' +
", rating='" + rating + '\'' +
", cast=" + cast +
'}';
}

}
Loading