//Prompts suer for id and returns movie. Updates inventory and adds return date to transactions
        public static void ReturnMovie()
        {
            Console.Clear();
            Console.WriteLine("\nRETURN MOVIE\n");

            TransactionFile tf = new TransactionFile();

            Transaction[] transList = tf.ReadFile();
            string        email     = ViewRentedMovies();

            int index = -1;
            int id    = -1;

            while (index == -1)
            {
                Console.WriteLine("\nEnter movie ID of movie to return: ");
                string input = Console.ReadLine();

                if (input.All(char.IsNumber))
                {
                    id    = int.Parse(input);
                    index = GetTransactionIndex(transList, id);

                    if (index == -1)
                    {
                        Console.WriteLine("\tError: Movie not found.");
                    }
                }
                else
                {
                    Console.WriteLine("\tError: Enter only numeric values.");
                }
            }
            String[] dateDelin  = DateTime.Now.ToString().Split(' ');
            String   returnDate = dateDelin[0];

            transList[index].SetReturnDate(returnDate);
            tf.WriteFile(transList);

            MovieFile mf = new MovieFile();

            Movie[] inv = mf.ReadFile();
            index = Program.GetMovieIndex(inv, id);
            inv[index].SetStock();
            Console.WriteLine($"\nReturned movie: {inv[index].ReadString()}");
            mf.WriteFile(inv);
        }
예제 #2
0
        //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());
                }
            }
        }
예제 #3
0
        //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()}");
                }
            }
        }
        //Prompts user for email and prints each movie rented by that email
        public static string ViewRentedMovies()
        {
            Console.WriteLine("\nEnter email address: ");
            String email = Console.ReadLine();

            Console.WriteLine("\nRENTED MOVIES\n");
            Console.WriteLine("\n\tTransaction ID\t|\tMovie ID\t|\tDate Rented|\tTitle\t");
            Console.WriteLine("\t-------------------------------------------------------------------------------------");

            TransactionFile tf = new TransactionFile();

            Transaction[] transList = tf.ReadFile();
            MovieFile     mf        = new MovieFile();

            Movie[] movieInv = mf.ReadFile();

            for (int i = 0; i < transList.Length; i++)
            {
                if (transList[i].GetEmail() == email)
                {
                    if (transList[i].GetReturnDate() == "Not Returned")
                    {
                        string rented  = transList[i].GetRentDate();
                        int    transID = transList[i].GetTransID();

                        int    movieID = transList[i].GetMovieID();
                        int    index   = Program.GetMovieIndex(movieInv, movieID);
                        string title   = movieInv[index].GetTitle();

                        string space = "\t\t|\t";
                        Console.WriteLine($"\t{transID}{space}{movieID}{space}{rented}{space}{title}");
                    }
                }
            }
            return(email);
        }
        //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);
        }
예제 #6
0
        //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}");
        }