private static MovieCollection instance; // creating a instance of class MovieCollection public static MovieCollection getInstance() // this function returns the object of class MovieCollection { if (instance == null) { instance = new MovieCollection(); } return(instance); }
public void menu(int index)// this function display the member menu { MovieCollection movieCollection = MovieCollection.getInstance(); while (true) { Console.WriteLine("===========Member Menu==========="); Console.WriteLine("1. Display all movie"); Console.WriteLine("2. Borrow a movie DVD"); Console.WriteLine("3. Return a movie DVD"); Console.WriteLine("4. List current borrowed movie DVDs"); Console.WriteLine("5. Display top 10 most popular movies"); Console.WriteLine("6. Change your password"); Console.WriteLine("0. Return to main menu"); Console.WriteLine("================================"); Console.WriteLine(""); Console.WriteLine("Please make selection (1-6 or 0 to return to main menu)"); try { int staffChoice = Convert.ToInt32(Console.ReadLine()); switch (staffChoice) { case 1: movieCollection.showAllMovie(); break; case 2: Console.WriteLine("Enter the movie name you want to borrow"); string movieName = Console.ReadLine(); bool checkMovie = movieCollection.checkMovie(movieName); // this check if the if the movie exists in the library or not if (checkMovie == true) { int checkBorrowedMoviesCount = memberCollection[index].checkTotalBorrowedMovie(); //it gives the current number of moives borrowed by the member if (checkBorrowedMoviesCount < 11) // if the borrowed cout is less than 11 { bool checkIfAlreadyBorrowed = memberCollection[index].checkIfAlreadyBorrowed(movieName); // if the user have already borrowed that movie if (checkIfAlreadyBorrowed == true) { Console.WriteLine("You have already borrowed this movie"); } else { memberCollection[index].borrowMovie(movieName); // borrow the movie to the user Console.WriteLine("You have borrowed this movie"); } } else { Console.WriteLine("You currently have borrowed 10 movies you cannot borrow more"); } } else { Console.WriteLine("No movie with this name exists in the library"); } break; case 3: Console.WriteLine("Enter the movie name you want to return"); string returnMovieName = Console.ReadLine(); bool checkBorrowed = memberCollection[index].checkBorrowed(returnMovieName);// check if the user have borrowed that movie or not if (checkBorrowed == true) { memberCollection[index].returnMovie(returnMovieName); // returns the movie Console.WriteLine("Movie have been returned"); } else { Console.WriteLine("You donot have borrowed this movie"); } break; case 4: memberCollection[index].currentBorrowedMovie(); // display the current borrowed movie by the user break; case 5: Console.WriteLine("Top 10 most popular movies "); movieCollection.sort(); // first sort the movies in the descending order of the borrowed count movieCollection.showTop_10(); // display the top 10 movies after the sorting break; case 6: Console.WriteLine("Enter 4 digit new password"); while (true) { string newPassword = Console.ReadLine(); Regex reg = new Regex(@"^[0-9]{4}$"); if (reg.IsMatch(newPassword)) // check wheather the password entered is integer of 4 digits { memberCollection[index].setPassword(newPassword); // change the password Console.WriteLine("Password have been changed"); break; } else { Console.WriteLine("Enter a valid four digit password"); } } break; case 0: return; default: Console.WriteLine("Wrong input. Try Again"); break; } } catch (FormatException f) { Console.WriteLine("Error: Enter only integer values"); } } }