// Function that takes a member and movie object and removes the movie // from the members movie collection if the movie exists. // No output. public void RemoveMovieFromMember(Member member, Movie movie) { // Flag used to check if movie is currently already rented out. bool check = false; // Check to see if movie is an object or null based off parameter input. if (movie != null) { // Use CheckMovie function to check if the member current has // the movie rented out check = CheckMovie(member, movie); // If they do have the movie rented out, remove from their // collection. if (check) { member.RemoveBorrowedMovie(movie); movie.IncreaseCopiesAvail(1); Console.WriteLine(movie.GetTitle() + " returned to database by " + member.GetUsername() + "."); } else { Console.WriteLine("You do not have that movie currently rented out."); } } else { Console.WriteLine("The movie you entered does not exist."); } }
// Function that controls user input when prompting user to enter new // movie details. public static void Insert(MovieCollection.MovieTree BST) { Console.WriteLine(); Console.WriteLine(); Console.WriteLine("----ENTER MOVIE DETAILS----"); Console.WriteLine(); // Create flag used to check user input. bool correct = false; // Prompt user to enter movie title Console.Write("Enter movie title: "); string movieTitle = Console.ReadLine();; // Enter movie title. while (!correct) { correct = CheckInput(movieTitle, 0); if (!correct) { Console.Write("Enter movie title: "); movieTitle = Console.ReadLine(); } } // Check to see if the movie exists // in the BST before creating a new copy. Movie movieExists = BST.ReturnMovie(BST.ReturnRoot(), movieTitle); // If the movie exists, prompt user to enter an amount to add to database. if (movieExists != null) { Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Movie already" + " exists in database: How many" + " copies do you want to add?"); correct = false; int n = 0; correct = int.TryParse(Console.ReadLine(), out int movieAmount); // Check user input while (!correct || movieAmount <= 0 || movieAmount >= 1000) { if (!correct || movieAmount <= 0 || movieAmount >= 1000) { Console.Write("Please enter a number for copies " + "between 1 and 1000: "); } correct = int.TryParse(Console.ReadLine(), out movieAmount); } n = movieAmount; Console.WriteLine(); Console.WriteLine(); // Increase copies available by number movieExists.IncreaseCopiesAvail(n); Console.WriteLine(movieExists.GetTitle() + " copies increased by " + n); } // If movie doesnt exist prompt user for input about movie. else { // Check user input for actors Console.WriteLine(); correct = false; Console.Write("Enter starring actors: "); string starring = Console.ReadLine(); while (!correct) { correct = CheckInput(starring, 1); if (!correct) { Console.Write("Enter starring actors: "); starring = Console.ReadLine(); } } // Check user input for directors Console.WriteLine(); correct = false; Console.Write("Enter movie director: "); string director = Console.ReadLine(); while (!correct) { correct = CheckInput(director, 1); if (!correct) { Console.Write("Enter movie director: "); director = Console.ReadLine(); } } // Check user input for genre Console.WriteLine(); correct = false; string genre = "empty"; Console.WriteLine("Choose Genre: \n" + "1. Drama\n" + "2. Family\n" + "3. Action\n" + "4. SciFi\n" + "5. Comedy\n" + "6. Animated\n" + "7. Thriller\n" + "8. Other\n" + "Enter Number between 1-8: "); correct = int.TryParse(Console.ReadLine(), out int num); while (!correct || num <= 0 || num >= 9) { Console.WriteLine("Please enter a number between 1 and 8."); correct = int.TryParse(Console.ReadLine(), out num); } // Set genre based off switch case switch (num) { case 1: genre = "Drama"; break; case 2: genre = "Family"; break; case 3: genre = "Action"; break; case 4: genre = "SciFi"; break; case 5: genre = "Comedy"; break; case 6: genre = "Animated"; break; case 7: genre = "Thriller"; break; case 8: genre = "Other"; break; default: break; } // Check user input for classification Console.WriteLine(); correct = false; string classification = "empty"; Console.Write("Enter classification: \n" + "1. G\n" + "2. PG\n" + "3. M 15+\n" + "4. MA 15+\n" + "5. R 18+\n" + "Enter Number between 1-5: "); correct = int.TryParse(Console.ReadLine(), out num); while (!correct || num <= 0 || num >= 6) { Console.WriteLine("Please enter a number between 1 and 5."); correct = int.TryParse(Console.ReadLine(), out num); } // Set classification based off switch case switch (num) { case 1: classification = "G"; break; case 2: classification = "PG"; break; case 3: classification = "M 15+"; break; case 4: classification = "MA 15+"; break; case 5: classification = "R 18+"; break; default: break; } // Check user input for duration Console.WriteLine(); correct = false; int duration = 0; Console.Write("Enter duration: "); correct = int.TryParse(Console.ReadLine(), out num); while (!correct || num <= 0 || num >= 600) { Console.WriteLine("Please enter a number for duration " + "- 1.30 hr = 90 min for example."); Console.WriteLine(); Console.Write("Enter duration: "); correct = int.TryParse(Console.ReadLine(), out num); } duration = num; // Check user input for date Console.WriteLine(); DateTime releaseDate = DateTime.Now; correct = false; while (!correct) { try { Console.Write("Enter release date (dd/mm/yyyy): "); releaseDate = DateTime.Parse(Console.ReadLine()); correct = true; } catch (FormatException) { Console.WriteLine("Wrong date and time format - please enter dd/mm/yyyy"); Console.WriteLine(); } } // Check user input for amount of copies Console.WriteLine(); correct = false; int copiesAvail = 1; Console.Write("Enter amount of copies: "); correct = int.TryParse(Console.ReadLine(), out num); while (!correct || num <= 0 || num >= 1000) { Console.WriteLine("Please enter a number for copies " + "between 1 and 1000."); Console.WriteLine(); Console.Write("Enter amount of copies: "); correct = int.TryParse(Console.ReadLine(), out num); } copiesAvail = num; //Create new movie and it to BST tree. Console.WriteLine(); Movie movie = new Movie(movieTitle, starring , director, duration, genre, classification, releaseDate, copiesAvail, 0); Console.WriteLine("New movie " + movie.GetTitle() + " added to database."); BST.Insert(movie); } }