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)); }
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; } }
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); }
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)); } }