//Process transaction file and counts number of rentals for each movie and stores that count in a 2d array along with respective movie id //Then bubble sorts the 2d array and prints top 5 public static void Top5Rented() { Console.Clear(); Console.WriteLine("\nTOP 5 RENTED MOVIES\n"); TransactionFile tf = new TransactionFile(); Transaction[] trans = tf.ReadFile(); int[,] counts = new int[tf.GetCount(), 2]; for (int i = 0; i < tf.GetCount(); i++) { counts[trans[i].GetMovieID(), 0]++; counts[trans[i].GetMovieID(), 1] = trans[i].GetMovieID(); } //Bubble sorts for (int i = 0; i < tf.GetCount(); i++) { for (int j = 0; j < tf.GetCount() - 1; j++) { if (counts[j, 0] < counts[j + 1, 0]) { int[,] temp = { { counts[j, 0], counts[j, 1] } }; counts[j, 0] = counts[j + 1, 0]; counts[j, 1] = counts[j + 1, 1]; counts[j + 1, 0] = temp[0, 0]; counts[j + 1, 1] = temp[0, 1]; } } } //prints top 5 for (int i = 0; i < 5; i++) { if (counts[i, 0] != 0) { Console.WriteLine($"#{i+1}\t\tID: {counts[i, 1]}\t|\tCount: {counts[i,0]}\t|\t{Program.GetMovie(counts[i, 1]).GetTitle()}"); } } }
//Prints rented movies public static void RentedMovies() { Console.Clear(); Console.WriteLine("\nRENTED MOVIES\n"); TransactionFile tf = new TransactionFile(); Transaction[] trans = tf.ReadFile(); for (int i = 0; i < tf.GetCount(); i++) { if (trans[i].GetReturnDate() == "Not Returned") { Console.WriteLine(trans[i].ReadString()); } } }
//Prompts user for id and rents movie. Updates inventory and adds to transactions public static void RentMovie() { Console.Clear(); Console.WriteLine("\nRENT MOVIE\n"); String input; int id; int index = -1; TransactionFile tf = new TransactionFile(); MovieFile mf = new MovieFile(); Movie[] movieInventory = mf.ReadFile(); ViewAvailableMovies(); Console.WriteLine("\nEnter email address: "); String email = Console.ReadLine(); while (index == -1) { Console.WriteLine("\nEnter movie ID to rent:\t(Enter 0 to input movie title instead)"); input = Console.ReadLine(); if (input.All(char.IsNumber)) { id = int.Parse(input); if (id == 0) { Console.WriteLine("\nEnter movie title to rent: "); input = Console.ReadLine(); index = Program.GetMovieIndex(movieInventory, input); } else { index = Program.GetMovieIndex(movieInventory, id); } if (index == -1) { Console.WriteLine("\tError: Movie not found."); } } else { Console.WriteLine("\tError: Enter only numeric values."); } if (index != -1) { if (movieInventory[index].GetStock() == false) { Console.WriteLine("\tError: Selected movie is unavailable. Please select a different movie."); index = -1; } } } movieInventory[index].SetStock(); mf.WriteFile(movieInventory); String[] dateDelin = DateTime.Now.ToString().Split(' '); String rentDate = dateDelin[0]; Transaction[] transactions = tf.ReadFile(); tf.IncrementCount(); Transaction newTransaction = new Transaction(tf.GetID(), email, movieInventory[index].GetMovieID(), rentDate); int count = tf.GetCount(); Transaction[] updatedTransactions = new Transaction[count]; for (int i = 0; i < count - 1; i++) { updatedTransactions[i] = transactions[i]; } updatedTransactions[updatedTransactions.Length - 1] = newTransaction; Console.WriteLine($"\nRented movie: {movieInventory[index].ReadString()}"); tf.WriteFile(updatedTransactions); }
//Sequential sorts the transactions by genre then processes transactions again keeping count and printing count by genre public static void RentedGenresCount() { String[] GENRES = { "Action", "Family", "Horror", "Sci-Fi", "Comedy", "Other" }; Console.Clear(); Console.WriteLine("\nRENT COUNT BY GENRE\n"); TransactionFile tf = new TransactionFile(); Transaction[] trans = tf.ReadFile(); Transaction tempTran; Movie tempMovie = Program.GetMovie(trans[0].GetMovieID()); Movie tempMovie2 = Program.GetMovie(trans[1].GetMovieID()); String holdGenre = tempMovie.GetGenre(); String currGenre = tempMovie2.GetGenre(); //Bubble sorts transactions for (int i = 0; i < tf.GetCount(); i++) { tempMovie = Program.GetMovie(trans[i].GetMovieID()); holdGenre = tempMovie.GetGenre(); for (int j = i + 1; j < tf.GetCount(); j++) { tempMovie2 = Program.GetMovie(trans[j].GetMovieID()); currGenre = tempMovie2.GetGenre(); if (holdGenre.CompareTo(currGenre) > 0) { tempTran = trans[j]; trans[j] = trans[i]; trans[i] = tempTran; tempMovie = Program.GetMovie(trans[i].GetMovieID()); holdGenre = tempMovie.GetGenre(); } } } //Prints genre count tempMovie = Program.GetMovie(trans[0].GetMovieID()); currGenre = tempMovie.GetGenre(); int count = 0; Console.WriteLine("Genre \t| Count"); for (int i = 0; i < tf.GetCount(); i++) { tempMovie = Program.GetMovie(trans[i].GetMovieID()); if (currGenre == tempMovie.GetGenre()) { count++; } else { Console.WriteLine($"{currGenre} \t| {count}"); tempMovie = Program.GetMovie(trans[i].GetMovieID()); currGenre = tempMovie.GetGenre(); count = 0; } } Console.WriteLine($"{currGenre} \t| {count}"); }