/** * A method to append a borrower's array of borrowed movies. * This doesn't increase or decrease the borrowers of the Management system. * * Asuming that a customer cannot borrow the same movie more than once. */ public void appendBorrowerMovie(Borrower b, string movieTitle) { //searches if the movie is available in the management system. DVD searchedDVD = binaryDVDTree.search(movieTitle); //if the seachedDVD is not null then add the movie to the borrower's array of movies. if (searchedDVD != null) { //check if only 1 copy of the movie is left if (searchedDVD.getQuantity() == 1) { //delete the movie from the collection binaryDVDTree.Delete(searchedDVD); } //check if more than 1 copy is available else if (searchedDVD.getQuantity() > 1) { //decrease the quantity of that movie. searchedDVD.decreaseQuantity(); } b.addRentedMovie(searchedDVD); } }
public void ReturnMovie() { Console.Clear(); Console.WriteLine("-----------------Return a Movie------------------\r"); Console.WriteLine("Phone Number of the Customer:"); string phoneNumInput = Console.ReadLine(); //check if phone number exists. if (DVDCollection.checkPhoneBorrower(phoneNumInput) == 100) { Console.WriteLine("Customer with the provided phone number (" + phoneNumInput + ") doesn't exist."); Console.WriteLine("Press enter to continue."); Console.ReadLine(); displayReturnMovie = false; displayBorrower = true; } else { Borrower existingBorrower = DVDCollection.getBorrower(DVDCollection.GetBorrowerWithPhone(phoneNumInput)); Console.WriteLine("Title of the movie that is being returned:"); string returnTitleInput = Console.ReadLine(); if (DVDCollection.checkExistingDVD(existingBorrower, returnTitleInput) != null) { DVDCollection.insertDVD(DVDCollection.checkExistingDVD(existingBorrower, returnTitleInput)); } else if (DVDCollection.checkExistingDVD(existingBorrower, returnTitleInput) == null) { Console.WriteLine("The movie with the title - " + returnTitleInput + " was not rented by " + existingBorrower); Console.WriteLine("press enter to continue..."); Console.ReadLine(); } } displayReturnMovie = false; displayBorrower = true; }
//checks if the borrower exists in the borrowersQueue. //linear check. Big-O = O(n) //100 = doesn't exist //if it returns 100 then the borrower doesn't exists in the array public int checkBorrower(Borrower b) { int result = 100; for (int i = 0; i < borrowersArr.Length; i++) { if (borrowersArr[i] != null) { if (b.getPhoneNum().CompareTo(borrowersArr[i].getPhoneNum()) == 0) { result = i; } } } return(result); /* if (binarySearch(borrowerArr, b.getPhoneNum()) != 100) * { * result = binarySearch(borrowerArr, b.getPhoneNum()); * } * return result;*/ }
public DVD checkExistingDVD(Borrower b, string movieTitle) { return(b.removeDVD(movieTitle)); }
public void LendMovie() { Console.Clear(); Console.WriteLine("------------------Lend a Movie------------------\r"); Console.WriteLine("Title of the movie that customer wants to borrow:"); string movieTitleInput = Console.ReadLine(); //check if there is a movie with the inputed title. if (DVDCollection.searchMyCollection(movieTitleInput) != null) { Console.WriteLine("Customer First Name:"); string firstNameInput = Console.ReadLine(); Console.WriteLine("Customer Last Name:"); string lastNameInput = Console.ReadLine(); Console.WriteLine("Customer Contact Number:"); string phoneInput = Console.ReadLine(); //check if movie with that title exists. else tell inform that movie doesnt exist. //check if customer with those details exist -> append just the borrower's DVDArr //else if no customer exist -> add details with the movie to borrowerArr //the dvd that will be added to the borrower's DVDArr. DVD movieBorrowed = DVDCollection.searchMyCollection(movieTitleInput); Console.WriteLine(movieBorrowed.getTitle()); Borrower customer = new Borrower(firstNameInput, lastNameInput, phoneInput, new DVD[10]); //check if borrower's details already exist in DVDCollection if (DVDCollection.checkBorrower(customer) != 100) { Console.WriteLine(DVDCollection.checkBorrower(customer)); DVDCollection.appendBorrowerMovie(DVDCollection.getBorrower(DVDCollection.checkBorrower(customer)), movieTitleInput); } //else add the customer to the management system and //then add the movie to that customers borrowed movies array. else { DVDCollection.addBorrower(customer); DVDCollection.appendBorrowerMovie(customer, movieTitleInput); Console.WriteLine(); Console.WriteLine("Customer has been added. Press enter to continue."); Console.ReadLine(); } //check if borrower exists /* if (DVDCollection.checkBorrower(customer) != 100) * { * // append the movie of the borrower that exists in the datastructre. * DVDCollection.appendBorrowerMovie( * DVDCollection.getBorrower(DVDCollection.checkBorrower(customer)), * movieTitleInput); * } * //else add the customer to the management system and * //then add the movie to that customers borrowed movies array. * else * { * DVDCollection.addBorrower(customer); * DVDCollection.appendBorrowerMovie(customer, movieTitleInput); * }*/ displayLendMovie = false; displayBorrower = true; } /*foreach (Borrower oldCustomer in DVDCollection.getBorrowerArr()) // O(n) * { * if (oldCustomer.getPhoneNum().CompareTo(contactInput) == 0) //as the phone number is unique * { * * * //oldCustomer.addMoreMovies(movieTitleInput); * } * else * { * DVDCollection.addBorrower(newBorrower); * DVDCollection.addMovie(newBorrower, movieTitleInput); * } * }*/ }