public void findMemberPhoneNumber(MemberCollection myMemberCollection) { string input = ""; string findMemberPhoneNumberMenu = "===========FIND MEMBER PHONE NUMBER=============\n"; Console.WriteLine(findMemberPhoneNumberMenu); bool foundMatch = false; string phoneNumber = ""; while (foundMatch == false) { Console.Write("Username: "******"\nError: A member with that username could not be found.\n"); break; } } if (foundMatch == true) { Console.WriteLine("Member with username {0} has the phone number {1}\n", input, phoneNumber); } }
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; } } }
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 Member registerMember(MemberCollection myMemberCollection) { Member myMember; string firstName = ""; string lastName = ""; string streetNumber; string streetName = ""; string streetType = ""; string suburb = ""; string postcode; string state = ""; string phoneNumber; string password; Console.WriteLine("===========Register Member============\n"); Console.Write("First Name: "); firstName = Console.ReadLine(); Console.Write("Last Name: "); lastName = Console.ReadLine(); //Iterate through the member collection and see if this member already exists for (int i = 0; i < myMemberCollection.Members.Length; i++) { //If there exists members and if that member exists if (myMemberCollection.AmountOfMembers > 0 && myMemberCollection.Members[i].getUserName() == (lastName + firstName)) { return(null); } } //Parse street number while (true) { Console.Write("Street Number: "); if (Int32.TryParse(Console.ReadLine(), out int streetNumberInt)) { streetNumber = streetNumberInt.ToString(); break; } else { Console.WriteLine("Error: Enter a valid digit"); } } Console.Write("Street Name: "); streetName = Console.ReadLine(); Console.Write("Street Type: "); streetType = Console.ReadLine(); Console.Write("Suburb: "); suburb = Console.ReadLine(); //Parse postcode while (true) { Console.Write("Postcode: "); if (Int32.TryParse(Console.ReadLine(), out int postcodeInt)) { postcode = postcodeInt.ToString(); break; } Console.WriteLine("Error: That's not a valid postcode."); } Console.Write("State: "); state = Console.ReadLine(); //Parse phone Number while (true) { Console.Write("Phone Number: "); string input = Console.ReadLine(); //Ensures the phone number is an int if (Int64.TryParse(input, out long phoneNumberLong)) { phoneNumber = input; break; } else { Console.WriteLine("Error: That's not a valid phone number."); } } //Enter password while (true) { while (true) { Console.Write("Password: "******"0000" || (Int32.TryParse(input, out int passwordInt) && Math.Floor(Math.Log10(passwordInt) + 1) == 4)) { //Convert the int to a string to store password = input; break; } else { Console.WriteLine("\nError: Password was not valid. Trying entering a valid integer that's 4 digits long.\n"); } } Console.Write("Confirm Password: "******"Passwords don't match. Try again."); } } myMember = new Member(firstName, lastName, streetNumber, streetName, streetType, suburb, postcode, state, phoneNumber, password); return(myMember); }