Beispiel #1
0
 public static Member _current;           //Stores user that is currently logged in, staff or member
 //Main process
 //Input: string[] args
 //Output: None
 static void Main(string[] args)
 {
     _library = DummyMovies();
     _members = DummyMembers();
     _staff   = StaffList();
     MainMenu();
 }
Beispiel #2
0
 //Recursive function for creating nodes inside the new subcollection
 //Input: MovieNode current node of old tree, MovieCollection new subcollection, int start, int end, int index of node to be visited, string sorting method
 //Output: int index of how many items have already been traversed, current node from old tree added to subcollection if index is between start and end
 public int Subcollection(MovieNode root, MovieCollection sub, int start, int end, int index, string sort)
 {
     if (root != null && sort == "title")
     {
         index = Subcollection(root.Left, sub, start, end, index, sort);
         if (index >= start)
         {
             if (index >= end)
             {
                 return(index);
             }
             sub.Add(root.Movie);
         }
         index++;
         index = Subcollection(root.Right, sub, start, end, index, sort);
     }
     else if (root != null && sort == "top")
     {
         index = Subcollection(root.Right, sub, start, end, index, sort);
         if (index >= start)
         {
             if (index >= end)
             {
                 return(index);
             }
             sub.Add(root.Movie);
         }
         index++;
         index = Subcollection(root.Left, sub, start, end, index, sort);
     }
     return(index);
 }
Beispiel #3
0
        //Returns information about the top ten most borrowed movies in the library
        //Input: None
        //Output: Outputs the movies in a ranking system from 1. to 10. based on the
        //        amount of times they have been borrowed
        static void TopTen()
        {
            int size = _library.Size();

            if (size > 10)
            {
                size = 10;
            }
            int.TryParse(Math.Ceiling(size / 5.0).ToString(), out int pages);
            int currentPage = 1;

DisplayTopTen:
            Console.Clear();
            Console.WriteLine("Logged in as {0} {1}", _current.FirstName, _current.Surname);
            Console.WriteLine("=======Display top 10 most popular movies=======");
            MovieCollection top = _library.Subcollection(0, size, "top");

            top = top.Subcollection((currentPage - 1) * 5, (currentPage) * 5, "top");
            top.Display(currentPage);
            Console.Write("\n    Page: 0 (Return)");
            for (int i = 1; i <= pages; i++)
            {
                if (i == currentPage)
                {
                    Console.Write(" [{0}]", i.ToString());
                }
                else
                {
                    Console.Write("  {0} ", i.ToString());
                }
            }
            Console.WriteLine("\n================================================");
            ConsoleKeyInfo c = Console.ReadKey(true);

            if (c.Key == ConsoleKey.Escape)
            {
                return;
            }
            if (c.KeyChar.ToString() == "0")
            {
                return;
            }
            int.TryParse(c.KeyChar.ToString(), out int v);
            if (v > 0 && v <= pages)
            {
                currentPage = v <0 ? 0 : v> pages ? pages : v;
            }
            goto DisplayTopTen;
        }
Beispiel #4
0
        //Displays movies in pages of 2, with information about each movie
        //Input: Page number selection or return
        //Output: Display movie data from that page
        static void DisplayMovies()
        {
            int size = _library.Size();

            int.TryParse(Math.Ceiling(size / 2.0).ToString(), out int pages);
            int currentPage = 1;

DisplayMovies:
            Console.Clear();
            Console.WriteLine("Logged in as {0} {1}", _current.FirstName, _current.Surname);
            Console.WriteLine("===============Display all movies===============");
            MovieCollection currentMovies = _library.Subcollection(((currentPage - 1) * 2), ((currentPage) * 2));

            currentMovies.Display();
            Console.Write("\n    Page: 0 (Return)");
            for (int i = 1; i <= pages; i++)
            {
                if (i == currentPage)
                {
                    Console.Write(" [{0}]", i.ToString());
                }
                else
                {
                    Console.Write("  {0} ", i.ToString());
                }
            }
            Console.WriteLine("\n================================================");
            ConsoleKeyInfo c = Console.ReadKey(true);

            if (c.Key == ConsoleKey.Escape)
            {
                return;
            }
            if (c.KeyChar.ToString() == "0")
            {
                return;
            }
            int.TryParse(c.KeyChar.ToString(), out int v);
            if (v > 0 && v <= pages)
            {
                currentPage = v <0 ? 0 : v> pages ? pages : v;
            }
            goto DisplayMovies;
        }
Beispiel #5
0
        //Generates another MovieCollection which contains a subset of the current collection by in order traversal
        //Input: int start of new collection, int end of new collection, string new collection's sorting method (by title or borrowed)
        //Output: new MovieCollection of size (end-start) sorted by the given sorting technique
        public MovieCollection Subcollection(int start, int end, string sortBy = "title")
        {
            int size = this.Size();

            if (start > end)
            {
                (end, start) = (start, end);
            }
            if (start < 0)
            {
                start = 0;
            }
            if (end > size)
            {
                end = size;
            }
            MovieCollection sub   = new MovieCollection(sortBy);
            int             index = 0;

            Subcollection(root, sub, start, end, index, sub.sort);
            return(sub);
        }
Beispiel #6
0
        //Collection of dummy Movie() data for testing purposes
        static MovieCollection DummyMovies()
        {
            MovieCollection dummyLibrary = new MovieCollection();

            dummyLibrary.Add(new Movie(
                                 "The Irishman",
                                 new string[] {
                "Robert De Niro",
                "Al Pacino",
                "Joe Pesci",
            },
                                 "Martin Scorsese",
                                 209,
                                 Genre.Thriller,
                                 Classification.MA,
                                 new DateTime(2019, 11, 27),
                                 3
                                 ));
            dummyLibrary.Add(new Movie(
                                 "Once Upon a Time in Hollywood",
                                 new string[] {
                "Leonardo DiCaprio",
                "Brad Pitt",
                "Margot Robbie"
            },
                                 "Quentin Tarantino",
                                 161,
                                 Genre.Comedy,
                                 Classification.MA,
                                 new DateTime(2019, 8, 15),
                                 2
                                 ));
            dummyLibrary.Add(new Movie(
                                 "Avengers: Endgame",
                                 new string[] {
                "Robert Downey Jr.",
                "Chris Evans",
                "Mark Ruffalo"
            },
                                 "Anthony & Joe Russo",
                                 181,
                                 Genre.Adventure,
                                 Classification.M,
                                 new DateTime(2019, 4, 24),
                                 6
                                 ));
            dummyLibrary.Add(new Movie(
                                 "Parasite",
                                 new string[] {
                "Kang-ho Song",
                "Sun-kyun Lee",
                "Yeo-jeong Jo"
            },
                                 "Bong Joon Ho",
                                 132,
                                 Genre.Thriller,
                                 Classification.MA,
                                 new DateTime(2019, 5, 30),
                                 4
                                 ));
            dummyLibrary.Add(new Movie(
                                 "Marriage Story",
                                 new string[] {
                "Adam Driver",
                "Scarlett Johansson",
                "Julia Greer"
            },
                                 "Noah Baumbach",
                                 137,
                                 Genre.Drama,
                                 Classification.M,
                                 new DateTime(2019, 12, 6),
                                 4
                                 ));
            dummyLibrary.Add(new Movie(
                                 "Little Women",
                                 new string[] {
                "Saoirse Ronan",
                "Emma Watson",
                "Florence Pugh"
            },
                                 "Greta Gerwig",
                                 135,
                                 Genre.Drama,
                                 Classification.G,
                                 new DateTime(2020, 1, 1),
                                 2
                                 ));
            dummyLibrary.Add(new Movie(
                                 "Booksmart",
                                 new string[] {
                "Kaitlyn Dever",
                "Beanie Feldstein",
                "Jessica Williams"
            },
                                 "Olivia Wilde",
                                 102,
                                 Genre.Comedy,
                                 Classification.MA,
                                 new DateTime(2019, 6, 27),
                                 8
                                 ));
            dummyLibrary.Add(new Movie(
                                 "The Farewell",
                                 new string[] {
                "Shuzhen Zhao",
                "Awkwafina",
                "X Mayo"
            },
                                 "Lulu Wang",
                                 100,
                                 Genre.Drama,
                                 Classification.PG,
                                 new DateTime(2019, 9, 5),
                                 10
                                 ));
            dummyLibrary.Add(new Movie(
                                 "Knives Out",
                                 new string[] {
                "Daniel Craig",
                "Chris Evans",
                "Ana de Armas"
            },
                                 "Rian Johnson",
                                 131,
                                 Genre.Comedy,
                                 Classification.M,
                                 new DateTime(2019, 11, 28),
                                 15
                                 ));
            dummyLibrary.Add(new Movie(
                                 "Joker",
                                 new string[] {
                "Joaquin Phoenix",
                "Robert De Niro",
                "Zazie Beetz"
            },
                                 "Todd Phillips",
                                 122,
                                 Genre.Thriller,
                                 Classification.MA,
                                 new DateTime(2019, 10, 3),
                                 7
                                 ));
            dummyLibrary.Add(new Movie(
                                 "Toy Story 4",
                                 new string[] {
                "Tom Hanks",
                "Tim Allen",
                "Annie Potts"
            },
                                 "Josh Cooley",
                                 100,
                                 Genre.Family,
                                 Classification.G,
                                 new DateTime(2019, 6, 20),
                                 25
                                 ));
            dummyLibrary.Add(new Movie(
                                 "1917",
                                 new string[] {
                "Dean-Charles Chapman",
                "George MacKay",
                "Daniel Mays"
            },
                                 "Sam Mendes",
                                 119,
                                 Genre.Drama,
                                 Classification.MA,
                                 new DateTime(2020, 1, 16),
                                 8
                                 ));
            dummyLibrary.Add(new Movie(
                                 "Midsommar",
                                 new string[] {
                "Florence Pugh",
                "Jack Reynor",
                "Vilhelm Blomgren"
            },
                                 "Ari Aster",
                                 148,
                                 Genre.Thriller,
                                 Classification.MA,
                                 new DateTime(2019, 8, 8),
                                 3
                                 ));
            return(dummyLibrary);
        }
Beispiel #7
0
        //Adds a DVD of the user's choice to the library
        //Input: Information about a movie
        //Output: Movie movie added to MovieCollection _library
        static void AddDVD()
        {
            Console.Clear();
            Console.WriteLine("Logged in as {0} {1}", _current.FirstName, _current.Surname);
            Console.WriteLine("==============Add a new movie DVD===============");
            Console.WriteLine("   Please enter the movie's title\n");
            Console.WriteLine("   Or press 'Escape' to exit");
            Console.WriteLine("================================================\n");
            Console.Write(" Title: ");
            ConsoleKeyInfo key   = Console.ReadKey();
            string         title = "";

            if (key.Key == ConsoleKey.Escape)
            {
                return;
            }
            else
            {
                title += key.KeyChar.ToString();
            }
            title += Console.ReadLine();
            Console.Clear();
            Console.WriteLine("Logged in as {0} {1}", _current.FirstName, _current.Surname);
            Console.WriteLine("==============Add a new movie DVD===============");
            Console.WriteLine("   Please enter the movie's starring actors");
            Console.WriteLine("   Separate each star with a comma (,)");
            Console.WriteLine("================================================\n");
            Console.Write(" Stars: ");
            string[] parsedStarring = Console.ReadLine().Split(',');
            for (int i = 0; i < parsedStarring.Length; i++)
            {
                parsedStarring[i] = parsedStarring[i].TrimStart();
            }
            Console.Clear();
            Console.WriteLine("Logged in as {0} {1}", _current.FirstName, _current.Surname);
            Console.WriteLine("==============Add a new movie DVD===============");
            Console.WriteLine("   Please enter the movie's director");
            Console.WriteLine("================================================\n");
            Console.Write(" Director: ");
            string director = Console.ReadLine();

Runtime:
            Console.Clear();
            Console.WriteLine("Logged in as {0} {1}", _current.FirstName, _current.Surname);
            Console.WriteLine("==============Add a new movie DVD===============");
            Console.WriteLine("   Please enter the movie's runtime");
            Console.WriteLine("   Please give your response in minutes");
            Console.WriteLine("================================================\n");
            Console.Write(" Duration: ");
            if (!int.TryParse(Console.ReadLine(), out int parsedDuration))
            {
                Console.WriteLine("\n   Not a valid amount of time");
                Console.ReadKey(true);
                goto Runtime;
            }
Genre:
            Console.Clear();
            Console.WriteLine("Logged in as {0} {1}", _current.FirstName, _current.Surname);
            Console.WriteLine("==============Add a new movie DVD===============");
            Console.WriteLine("   Please enter the movie's genre");
            Console.WriteLine("   Choose between: Drama, Adventure,");
            Console.WriteLine("   Family, Action, Sci-Fi, Comedy,");
            Console.WriteLine("   Animated, Thriller or Other");
            Console.WriteLine("================================================\n");
            Console.Write(" Genre: ");
            string g = Console.ReadLine();

            if (g == "Sci-Fi")
            {
                g = "SciFi";
            }
            if (!Enum.TryParse(g, out Genre parsedGenre))
            {
                Console.WriteLine("\n   Not a valid genre");
                Console.ReadKey(true);
                goto Genre;
            }
Classification:
            Console.Clear();
            Console.WriteLine("Logged in as {0} {1}", _current.FirstName, _current.Surname);
            Console.WriteLine("===============Add a new movie DVD===============");
            Console.WriteLine("   Please enter the movie's classification");
            Console.WriteLine("   Choose: G (General)");
            Console.WriteLine("           PG (Parental Guidance)");
            Console.WriteLine("           M (Mature)");
            Console.WriteLine("           MA (Mature Accompanied)");
            Console.WriteLine("================================================\n");
            Console.Write(" Classification: ");
            if (!Enum.TryParse(Console.ReadLine(), out Classification parsedClassification))
            {
                Console.WriteLine("\n   Not a valid Classification");
                Console.ReadKey(true);
                goto Classification;
            }
ReleaseDate:
            Console.Clear();
            Console.WriteLine("Logged in as {0} {1}", _current.FirstName, _current.Surname);
            Console.WriteLine("==============Add a new movie DVD===============");
            Console.WriteLine("   Please enter the release date");
            Console.WriteLine("================================================\n");
            Console.Write(" Release Date: ");
            if (!DateTime.TryParse(Console.ReadLine(), out DateTime parsedReleaseDate))
            {
                Console.WriteLine("\n   Not a valid Date");
                Console.ReadKey(true);
                goto ReleaseDate;
            }
Copies:
            Console.Clear();
            Console.WriteLine("Logged in as {0} {1}", _current.FirstName, _current.Surname);
            Console.WriteLine("==============Add a new movie DVD===============");
            Console.WriteLine("   Please enter the amount of DVDs you");
            Console.WriteLine("   would like to add");
            Console.WriteLine("================================================\n");
            Console.Write(" Copies: ");
            if (!int.TryParse(Console.ReadLine(), out int parsedCopies))
            {
                Console.WriteLine("\n   Not a valid amount of copies");
                Console.ReadKey(true);
                goto Copies;
            }
Final:
            Console.Clear();
            Console.WriteLine("Logged in as {0} {1}", _current.FirstName, _current.Surname);
            Console.WriteLine("==============Add a new movie DVD===============");
            Console.WriteLine("   Do you want to add this movie?\n");
            Console.WriteLine("   {0, -15} {1, 29}", "Title:", title);
            Console.WriteLine("   {0, -15} {1, 29}", "Stars:", MovieCollection.Truncate(string.Join(", ", parsedStarring)));
            Console.WriteLine("   {0, -15} {1, 29}", "Director:", director);
            Console.WriteLine("   {0, -15} {1, 29}", "Duration:", parsedDuration.ToString() + " minutes");
            Console.WriteLine("   {0, -15} {1, 29}", "Genre:", parsedGenre.ToString());
            Console.WriteLine("   {0, -15} {1, 29}", "Classification:", parsedClassification.ToString());
            Console.WriteLine("   {0, -15} {1, 29}", "Release Date:", parsedReleaseDate.ToString("d", CultureInfo.CreateSpecificCulture("es-ES")));
            Console.WriteLine("   {0, -15} {1, 29}", "Copies:", parsedCopies.ToString());
            Console.WriteLine("================================================\n");
            Console.Write(" yes/no: ");
            string res = Console.ReadLine();

            switch (res)
            {
            case ("yes"):
            case ("Yes"):
            case ("y"):
            case ("Y"):
                AddDVD(title, parsedStarring, director, parsedDuration, parsedGenre, parsedClassification, parsedReleaseDate, parsedCopies);
                Console.WriteLine("\n   Successfully added {0} to the library", title);
                Console.ReadKey(true);
                break;

            case ("no"):
            case ("No"):
            case ("n"):
            case ("N"):
                break;

            default:
                goto Final;
            }
        }
Beispiel #8
0
        //Remove a DVD of the user's choice from the library
        //Input: Movie title
        //Output: Movie removed from MovieCollection _library
        static void RemoveDVD()
        {
RemoveStart:
            Console.Clear();
            Console.WriteLine("Logged in as {0} {1}", _current.FirstName, _current.Surname);
            Console.WriteLine("===============Remove a movie DVD===============");
            Console.WriteLine("   Please enter the title of the movie");
            Console.WriteLine("   you wish to remove\n");
            Console.WriteLine("   Or press 'Escape' to exit");
            Console.WriteLine("================================================\n");
            Console.Write(" Title: ");
            ConsoleKeyInfo key   = Console.ReadKey();
            string         title = "";

            if (key.Key == ConsoleKey.Escape)
            {
                return;
            }
            else
            {
                title += key.KeyChar.ToString();
            }
            title += Console.ReadLine();
            if (_library.Find(title) == null)
            {
                Console.WriteLine("\n   Could not find movie {0}", title);
                Console.ReadKey(true);
                goto RemoveStart;
            }
            Movie toBeRemoved = _library.Find(title);

RemoveConfirm:
            Console.Clear();
            Console.WriteLine("Logged in as {0} {1}", _current.FirstName, _current.Surname);
            Console.WriteLine("===============Remove a movie DVD===============");
            Console.WriteLine("   Do you want to remove this movie?\n");
            Console.WriteLine("   {0, -15} {1, 29}", "Title:", toBeRemoved.Title);
            Console.WriteLine("   {0, -15} {1, 29}", "Stars:", MovieCollection.Truncate(string.Join(", ", toBeRemoved.Starring)));
            Console.WriteLine("   {0, -15} {1, 29}", "Director:", toBeRemoved.Director);
            Console.WriteLine("   {0, -15} {1, 29}", "Duration:", toBeRemoved.Duration.ToString() + " minutes");
            Console.WriteLine("   {0, -15} {1, 29}", "Genre:", toBeRemoved.Genre.ToString());
            Console.WriteLine("   {0, -15} {1, 29}", "Classification:", toBeRemoved.Classification.ToString());
            Console.WriteLine("   {0, -15} {1, 29}", "Release Date:", toBeRemoved.ReleaseDate.ToString("d", CultureInfo.CreateSpecificCulture("es-ES")));
            Console.WriteLine("   {0, -15} {1, 29}", "Copies:", toBeRemoved.Copies.ToString());
            Console.WriteLine("================================================\n");
            Console.Write(" yes/no: ");
            string res = Console.ReadLine();

            switch (res)
            {
            case ("yes"):
            case ("Yes"):
            case ("y"):
            case ("Y"):
                RemoveDVD(title);
                Console.WriteLine("\n   Successfully removed {0} from the library", title);
                Console.ReadKey(true);
                break;

            case ("no"):
            case ("No"):
            case ("n"):
            case ("N"):
                break;

            default:
                goto RemoveConfirm;
            }
        }