コード例 #1
0
        public string returnMovie(MovieCollection myBinaryTree)
        {
            string input = "";

            Console.Write("Enter movie title: ");
            input = Console.ReadLine();

            //Iterate through the members borrowed movies
            if (BorrowedMovies.Find(input) != null)
            {
                BorrowedMovies.Find(input).NumberOfCopiesRentedByThisUser--;
            }
            else
            {
                return(string.Format("You don't currently have any DVDs borrowed with the name '{0}'\n", input));
            }

            //If a member returned a movie that is present in the system.
            //Keep in mind if they returned a movie that wasn't present in the system, it's because staff deleted it from the BST
            if (myBinaryTree.Find(input) != null)
            {
                //Incrememt the number of copies for that movie that are available again
                myBinaryTree.Find(input).NumberOfCopiesAvailable++;
            }

            //This member has no copies of that movie left
            if (BorrowedMovies.Find(input).NumberOfCopiesRentedByThisUser == 0)
            {
                //Remove the movie entirely from the members borrowed movies
                BorrowedMovies.Remove(input);
                return(string.Format("You successfully returned your only DVD copy of '{0}'.\n", input));
            }
            //We only get to this point of the user has multiple copies of the same movie still in their possession
            return(string.Format("You successfully returned a DVD copy of '{0}'. You've still got {1} copies.\n", input, BorrowedMovies.Find(input).NumberOfCopiesRentedByThisUser));
        }
コード例 #2
0
        public string borrowMovie(MovieCollection myBinaryTree)
        {
            string input      = "";
            bool   foundMovie = false;

            Console.Write("Enter movie title: ");
            input = Console.ReadLine();

            //If the user input is a valid movie name but there are no dvd copies available
            if (myBinaryTree.Find(input) != null && myBinaryTree.Find(input).NumberOfCopiesAvailable == 0)
            {
                return(string.Format("Unfortunately, there are no DVD copies of the movie '{0}' in stock.\n", input));
            }
            //If we find a movie that has the title the user gave with available copies
            else if (myBinaryTree.Find(input) != null && myBinaryTree.Find(input).NumberOfCopiesAvailable >= 1)
            {
                //If the member already has that movie borrowed
                if (BorrowedMovies.Find(input) != null)
                {
                    //Increment the amount of copies that specific member has borrowed;
                    BorrowedMovies.Find(input).NumberOfCopiesRentedByThisUser++;
                    foundMovie = true;
                }


                //If foundMovie is still equal to false even after traversing through the user's currently borrowed movies, we know they don't currently
                //Have it borrowed
                if (!foundMovie)
                {
                    //Copy the data from the movies BST node into tempMovie
                    Movie tempMovie = new Movie
                                      (
                        myBinaryTree.Find(input).Title,
                        myBinaryTree.Find(input).Starring,
                        myBinaryTree.Find(input).Director,
                        myBinaryTree.Find(input).Duration,
                        myBinaryTree.Find(input).Genre,
                        myBinaryTree.Find(input).Classification,
                        myBinaryTree.Find(input).ReleaseDate,
                        myBinaryTree.Find(input).NumberOfCopiesThatExist
                                      );
                    tempMovie.NumberOfCopiesRentedByThisUser++;
                    BorrowedMovies.Insert(tempMovie);
                }

                //Decrement the total number of copies available
                myBinaryTree.Find(input).NumberOfCopiesAvailable--;
                //Incremet the total number of times borrowed for that specific movie
                myBinaryTree.Find(input).NumTimesBorrowed++;
                return(string.Format("You have successfully borrowed '{0}'.\n", input));
            }
            //The user gave a movie title which doesn't exist in the library
            else
            {
                return(string.Format("A movie with the title '{0}' doesn't exist.\n", input));
            }
        }
コード例 #3
0
 public Member(string firstName, string lastName, string streetNumber, string streetName, string streetType, string suburb, string postcode, string state, string phoneNumber, string password)
 {
     this.FirstName      = firstName;
     this.LastName       = lastName;
     this.StreetNumber   = streetNumber;
     this.StreetName     = streetName;
     this.StreetType     = streetType;
     this.Suburb         = suburb;
     this.Postcode       = postcode;
     this.State          = state;
     this.PhoneNumber    = phoneNumber;
     this.Password       = password;
     this.BorrowedMovies = new MovieCollection();
 }
コード例 #4
0
        static void Main(string[] args)
        {
            string input    = "";
            string mainMenu = "Welcome to the Community Library\n";

            mainMenu += "===========Main Menu============\n";
            mainMenu += "1. Staff Login\n";
            mainMenu += "2. Member Login\n";
            mainMenu += "0. Exit\n";
            mainMenu += "================================\n";
            string selection = "Please make a selection (1-2, or 0 to exit): ";

            string staffMenu = "===========Staff Menu=============\n";

            staffMenu += "1. Add a new movie DVD\n";
            staffMenu += "2. Remove a movie DVD\n";
            staffMenu += "3. Register a new Member\n";
            staffMenu += "4. Find a registered member's phone number\n";
            staffMenu += "0. Return to main menu\n";
            staffMenu += "=======================================\n";
            string selectionStaff = "Please make a selection (1-4 or 0 to return to main menu): ";

            string memberMenu = "===========Member Menu=============\n";

            memberMenu += "1. Display all movies\n";
            memberMenu += "2. Borrow a movie DVD\n";
            memberMenu += "3. Return a movie DVD\n";
            memberMenu += "4. List current borrowed movie DVDs\n";
            memberMenu += "5. Display top 10 most popular movies\n";
            memberMenu += "0. Return to main menu\n";
            memberMenu += "=======================================\n";
            string selectionMember = "Please make a selection (1-5 or 0 to return to main menu): ";

            bool inMainMenu = true;
            bool pickingMainMenuSelection = true;
            bool inStaffMenu         = false;
            bool staffMemberLoggedIn = false;

            bool pickingStaffMenuSelection = false;
            bool inMemberMenu = false;
            bool pickingMemberMenuSelection = false;
            bool memberLoggedIn             = false;
            int  memberNum = -1;

            StaffCollection myStaffCollection = new StaffCollection();
            Staff           myStaffMember     = new Staff("staff", "today123");

            myStaffCollection.addStaffMember(myStaffMember);

            MovieCollection  myBinaryTree       = new MovieCollection();
            MemberCollection myMemberCollection = new MemberCollection();

            //TEST FUNCTIONS
            myMemberCollection.addMember(new Member("Shaun", "Kickbusch", "21", "Daisy", "Street", "Brisbane", "4000", "QLD", "000000000", "0000"));
            myBinaryTree.Insert(new Movie("D", new string[3] {
                "Element 1", "Element 2", "Element 3"
            }, "A", "A", "A", "A", "A", 2));
            myBinaryTree.Insert(new Movie("C", new string[3] {
                "Element 1", "Element 2", "Element 3"
            }, "A", "A", "A", "A", "A", 2));
            myBinaryTree.Insert(new Movie("I", new string[3] {
                "Element 1", "Element 2", "Element 3"
            }, "A", "A", "A", "A", "A", 2));
            myBinaryTree.Insert(new Movie("J", new string[3] {
                "Element 1", "Element 2", "Element 3"
            }, "A", "A", "A", "A", "A", 2));
            myBinaryTree.Insert(new Movie("F", new string[3] {
                "Element 1", "Element 2", "Element 3"
            }, "A", "A", "A", "A", "A", 2));
            myBinaryTree.Insert(new Movie("E", new string[3] {
                "Element 1", "Element 2", "Element 3"
            }, "A", "A", "A", "A", "A", 2));
            myBinaryTree.Insert(new Movie("G", new string[3] {
                "Element 1", "Element 2", "Element 3"
            }, "A", "A", "A", "A", "A", 2));
            myBinaryTree.Insert(new Movie("H", new string[3] {
                "Element 1", "Element 2", "Element 3"
            }, "A", "A", "A", "A", "A", 2));

            //This while loop controls the whole flow of the program. E.g. if a member exits their member menu to return to the main menu it runs back to the
            //top of this loop
            while (true)
            {
                //This while loop controls the entire main menu. It sets bool values depending whether the user wants to progress to the staff or member menus
                while (inMainMenu == true)
                {
                    Console.WriteLine(mainMenu);
                    while (pickingMainMenuSelection == true)
                    {
                        Console.Write(selection);
                        input = Console.ReadLine();
                        if (input == "0")
                        {
                            Console.Write("Bye.");
                            System.Environment.Exit(1);
                        }
                        else if (input == "1" || input == "2")
                        {
                            pickingMainMenuSelection = false;
                            break;
                        }
                        Console.WriteLine("\nError: invalid option entered.\n");
                    }
                    if (input == "1")
                    {
                        inStaffMenu = true;
                        pickingStaffMenuSelection = true;
                    }
                    else if (input == "2")
                    {
                        pickingMemberMenuSelection = true;
                        inMemberMenu = true;
                    }
                    inMainMenu = false;
                }

                //This while loop controls the entire staff menu, from authentication to option selection
                while (inStaffMenu == true)
                {
                    while (staffMemberLoggedIn == false)
                    {
                        myStaffCollection.authentication();
                        staffMemberLoggedIn = true;
                    }

                    Console.WriteLine(staffMenu);
                    while (pickingStaffMenuSelection == true)
                    {
                        Console.Write(selectionStaff);
                        input = Console.ReadLine();
                        if (input == "0")
                        {
                            inMainMenu = true;
                            pickingMainMenuSelection = true;
                            inStaffMenu               = false;
                            staffMemberLoggedIn       = false;
                            pickingStaffMenuSelection = false;
                            break;
                        }
                        //Check if our input is a valid option
                        else if (input == "1" || input == "2" || input == "3" || input == "4")
                        {
                            pickingStaffMenuSelection = false;
                            break;
                        }
                        Console.WriteLine("\nError: Invalid Option Entered.\n");
                    }
                    //The staff member has selected option 1 which is "Add a new movie DVD"
                    if (input == "1")
                    {
                        Console.WriteLine("===========Add Movie=============");
                        Movie myMovie = myStaffMember.addMovie(myBinaryTree);
                        //If the function returned null, we updated the DVD copies for an existing movie
                        if (myMovie == null)
                        {
                        }
                        //If it returned true we created a brand new movie
                        else if (myMovie != null)
                        {
                            //Insert the new movie into the BST
                            myBinaryTree.Insert(myMovie);
                            Console.WriteLine("\nMovie Successfully Added.\n");
                        }
                    }
                    else if (input == "2")
                    {
                        myStaffMember.removeMovie(myBinaryTree, myMemberCollection);
                    }
                    else if (input == "3")
                    {
                        Member myMember = myStaffMember.registerMember(myMemberCollection);
                        //If the function returned null, that member already existed
                        if (myMember == null)
                        {
                            Console.WriteLine("\nError: Member already exists\n");
                        }
                        else if (myMember != null)
                        {
                            //Insert the new member into the member collection
                            myMemberCollection.addMember(myMember);
                            Console.WriteLine("\nMember Successfully Added.\n");
                        }
                    }
                    else if (input == "4")
                    {
                        myStaffMember.findMemberPhoneNumber(myMemberCollection);
                    }
                    pickingStaffMenuSelection = true;
                }

                while (inMemberMenu == true)
                {
                    while (memberLoggedIn == false)
                    {
                        //Store the index where the member appears to ensure we can access that same member later
                        memberNum      = myMemberCollection.authentication();
                        memberLoggedIn = true;
                    }

                    while (pickingMemberMenuSelection == true)
                    {
                        Console.WriteLine(memberMenu);
                        Console.Write(selectionMember);
                        input = Console.ReadLine();
                        if (input == "0")
                        {
                            inMainMenu = true;
                            pickingMainMenuSelection   = true;
                            inMemberMenu               = false;
                            memberLoggedIn             = false;
                            pickingMemberMenuSelection = false;
                            break;
                        }
                        else if (input == "1")
                        {
                            if (myBinaryTree.GetNumNodes() == 0)
                            {
                                Console.WriteLine("There's currently no movies in the library.\n");
                            }
                            //There's at least 1 movie in the library
                            else
                            {
                                //Display all movies
                                myBinaryTree.InOrderTraversal();
                            }
                        }
                        else if (input == "2")
                        {
                            //Borrow a movie
                            Console.WriteLine(myMemberCollection.Members[memberNum].borrowMovie(myBinaryTree));
                        }
                        else if (input == "3")
                        {
                            //Return a movie
                            Console.WriteLine(myMemberCollection.Members[memberNum].returnMovie(myBinaryTree));
                        }
                        else if (input == "4")
                        {
                            //List borrowed movies
                            myMemberCollection.Members[memberNum].currentlyBorrowed();
                        }
                        else if (input == "5")
                        {
                            //Create an array of movies with the size being the number of movies in the tree
                            Movie[] myMovies = new Movie[myBinaryTree.GetNumNodes()];
                            //Flatten the binary tree into the myMovies array
                            myBinaryTree.FlattenBST(myBinaryTree.Root, myMovies, 0);
                            //List top 10 movies
                            myBinaryTree.Top10MostPopularMovies(myMovies);
                        }
                        else
                        {
                            Console.WriteLine("\nError: Invalid Option Entered.\n");
                        }
                    }
                    inMemberMenu = false;
                }
            }
        }
コード例 #5
0
        public void removeMovie(MovieCollection myMovieCollection, MemberCollection myMemberCollection)
        {
            string input           = "";
            string removeMovieMenu = "===========REMOVE MOVIE=============\n";

            Console.WriteLine(removeMovieMenu);
            while (true)
            {
                Console.Write("Movie Title: ");
                input = Console.ReadLine();

                //Checks to see if we have that movie. If the find function returns null, that movie doesn't exist
                if (myMovieCollection.Find(input) == null)
                {
                    Console.WriteLine("The movie '{0}' currently doesn't exist in the library.", input);
                    break;
                }
                int numCopies = myMovieCollection.Find(input).NumberOfCopiesThatExist;
                //If there's only 1 instance, DVD, of the movie we instantly remove it
                if (numCopies == 1)
                {
                    myMovieCollection.Remove(input);
                    Console.WriteLine("The movie '{0}' was successfully removed.", input);
                    break;
                }
                //We get to this point if there's more than 1 DVD for that same movie. While loop is used to keep prompting
                //The user with the same Console.Write message if they enter an invalid input
                while (true)
                {
                    //If there's more than 1 DVD, we have to ask how many copies they'd like to remove
                    Console.Write("There's currently {0} DVD copies for '{1}.' How many would you like to remove? ", numCopies, input);

                    //See if the user input is an int
                    string temp = Console.ReadLine();
                    if (Int32.TryParse(temp, out int wantedAmount))
                    {
                        //See if the num DVD copies of that movie- the amount the user wants to remove is possible
                        if ((numCopies - wantedAmount) < 0)
                        {
                            Console.WriteLine("Error: You can't remove more copies of a movie than there exists.");
                        }
                        //If there's no copies of the movie left, we remove it
                        else if ((numCopies - wantedAmount) == 0)
                        {
                            myMovieCollection.Remove(input);
                            Console.WriteLine("The movie '{0}' was successfully removed.", input);
                            break;
                        }
                        //Else we have existing copies left so we update the movie in the tree
                        else
                        {
                            myMovieCollection.Find(input).NumberOfCopiesThatExist -= wantedAmount;
                            Console.WriteLine("Successfully removed {0} DVD copies for '{1}.' The updated amount of copies that exist is now {2}.", wantedAmount, input, myMovieCollection.Find(input).NumberOfCopiesThatExist);
                            break;
                        }
                    }
                    //We get to this point if the user input was unable to be parsed to an int
                    else
                    {
                        Console.WriteLine("Error: {0} is not a valid number.", temp);
                    }
                }
                break;
            }
        }
コード例 #6
0
        public Movie addMovie(MovieCollection myBinaryTree)
        {
            string        input               = "";
            string        movieTitle          = "";
            List <string> movieStarring       = new List <string>();
            string        movieDirector       = "";
            string        movieDuration       = "";
            string        movieGenre          = "";
            string        movieClassification = "";
            string        movieReleaseDate    = "";
            bool          addStar             = true;
            bool          addGenre            = true;
            bool          addClassification   = true;
            int           numCopies;
            Movie         myMovie;

            Console.Write("Title: ");
            input = Console.ReadLine();

            //Check if that movie already exists
            if (myBinaryTree.Find(input) != null)
            {
                Console.WriteLine("Error: A movie with that title already exists");
                while (true)
                {
                    //Since the movie already exists, ask the user if they'd like to update the number of DVD copies
                    Console.Write("Would you like to change the number of DVDs? (y or n): ");
                    string input2 = Console.ReadLine();
                    //The user wants to change the number of copies
                    if (input2 == "y")
                    {
                        while (true)
                        {
                            Console.Write("Copies: ");
                            if (Int32.TryParse(Console.ReadLine(), out int numTemp))
                            {
                                //If the number they entered is 0, we want to remove the movie
                                if (numTemp == 0)
                                {
                                    myBinaryTree.Remove(input);
                                    Console.WriteLine("Successfully removed the movie");
                                    //Exit the function
                                    return(null);
                                }
                                //The user entered a negative number
                                else if (numTemp < 0)
                                {
                                    Console.WriteLine("Error: you cannot enter a negative number.");
                                    //Go back to the start of the while loop
                                    continue;
                                }
                                int oldNumCopies = myBinaryTree.Find(input).NumberOfCopiesThatExist;
                                myBinaryTree.Find(input).NumberOfCopiesThatExist = numTemp;
                                Console.WriteLine("Successfully changed the num of copies for {0} from {1} to {2}.", input, oldNumCopies, myBinaryTree.Find(input).NumberOfCopiesThatExist);
                                return(null);
                            }
                            Console.WriteLine("Error: That's not a valid integer.");
                        }
                    }
                    else if (input2 == "n")
                    {
                        return(null);
                    }
                    else
                    {
                        Console.WriteLine("Error: {0} is not a valid option", input2);
                    }
                }
            }
            //We have a movie that doesn't exist
            else if (myBinaryTree.Find(input) == null)
            {
                movieTitle = input;
            }


            while (addStar == true)
            {
                Console.Write("Star: ");
                movieStarring.Add(Console.ReadLine());
                while (true)
                {
                    Console.Write("Add another star? (y or n): ");
                    input = Console.ReadLine();
                    if (input == "y")
                    {
                        break;
                    }
                    else if (input == "n")
                    {
                        addStar = false;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Error: Invalid Input.");
                    }
                }
            }
            Console.Write("Director: ");
            movieDirector = Console.ReadLine();

            while (addGenre == true)
            {
                Console.WriteLine("Select the genre: ");
                Console.WriteLine("1. Drama\n2. Adventure\n3. Family\n4. Action\n5. Sci-Fi\n6. Comedy\n7. Animated\n8. Thriller\n9. Other");
                Console.Write("Make selection (1-9): ");
                if (Int32.TryParse(Console.ReadLine(), out int genreSelection) && genreSelection >= 1 && genreSelection <= 9)
                {
                    switch (genreSelection)
                    {
                    case 1:
                        movieGenre = "Drama";
                        break;

                    case 2:
                        movieGenre = "Adventure";
                        break;

                    case 3:
                        movieGenre = "Family";
                        break;

                    case 4:
                        movieGenre = "Action";
                        break;

                    case 5:
                        movieGenre = "Sci-Fi";
                        break;

                    case 6:
                        movieGenre = "Comedy";
                        break;

                    case 7:
                        movieGenre = "Animated";
                        break;

                    case 8:
                        movieGenre = "Thriller";
                        break;

                    case 9:
                        movieGenre = "Other";
                        break;
                    }
                    addGenre = false;
                    break;
                }
                else
                {
                    Console.WriteLine("Error: Invalid Genre.");
                }
            }
            while (addClassification == true)
            {
                Console.WriteLine("Select the classification:");
                Console.WriteLine("1. General (G)\n2. Parental Guidance (PG)\n3. Mature (M15+)\n4. Mature Accompanied (MA15+)");
                Console.Write("Make selection (1-4): ");
                if (Int32.TryParse(Console.ReadLine(), out int classificationSelection) && classificationSelection >= 1 && classificationSelection <= 4)
                {
                    switch (classificationSelection)
                    {
                    case 1:
                        movieClassification = "G";
                        break;

                    case 2:
                        movieClassification = "PG";
                        break;

                    case 3:
                        movieClassification = "M15+";
                        break;

                    case 4:
                        movieClassification = "MA15+";
                        break;
                    }
                    addClassification = false;
                    break;
                }
                else
                {
                    Console.WriteLine("Error: Invalid Classification.");
                }
            }
            Console.Write("Duration (minutes): ");
            movieDuration = Console.ReadLine();

            Console.Write("Release Date (year): ");
            movieReleaseDate = Console.ReadLine();

            while (true)
            {
                Console.Write("Enter the number of copies available: ");
                if (Int32.TryParse(Console.ReadLine(), out numCopies))
                {
                    break;
                }
                Console.WriteLine("Error: Invalid number");
            }

            //Convert the list to an array
            string[] myArray = movieStarring.ToArray();
            myMovie = new Movie(movieTitle, myArray, movieDirector, movieDuration, movieGenre, movieClassification, movieReleaseDate, numCopies);
            return(myMovie);
        }