コード例 #1
0
        internal string GetRentables(bool available)
        {
            // get all the movies that were requested
            var rentables = Rentables.FindAll(r => r.IsAvailable == available);

            // if there are not short out and send back nothing
            if (rentables.Count == 0)
            {
                return("NOTHING HERE");
            }


            // create 2 lists one for movies, and one for "other"
            string movieList = "";

            movieList += available ? "Movies to Rent\n" : "Movies to Return\n";
            string others = "Other: \n";

            // itterate over the list of IRentables and check their types to add to the right list
            for (int i = 0; i < rentables.Count; i++)
            {
                var rentable = rentables[i];
                if (rentable is Movie)
                {
                    var movie = (Movie)rentable;
                    movieList += $"{i + 1}. {movie.Title} - {movie.Description}({movie.Year})\n";
                }
                else if (rentable is GameConsole)
                {
                    var con = (GameConsole)rentable;
                    others += $"{i + 1}. {con.Make} {con.Model} ({con.RentalCost}/week)\n";
                }
            }
            return(movieList + "\n\n" + others);
        }
コード例 #2
0
        internal string Return(int index)
        {
            var movies = Rentables.FindAll(m => !m.IsAvailable);

            if (index < movies.Count)
            {
                movies[index].IsAvailable = false;
                return("Thanks!");
            }
            return("Invalid Selection, You Ignoramus");
        }
コード例 #3
0
        internal string GetPurchasables()
        {
            var list = "ORDER FROM THE FOLLOWING: \n";
            List <IPurchasable> items = new List <IPurchasable>();

            items.AddRange(Snacks);
            // NOTE filter all rentables to only inclue things that can be purchased
            var purchasableRents = Rentables.FindAll(r => r is IPurchasable && r.IsAvailable);
            // NOTE Select functions like .map
            var rentItems = purchasableRents.Select(elem => (IPurchasable)elem);

            items.AddRange(rentItems);

            for (int i = 0; i < items.Count; i++)
            {
                IPurchasable item = items[i];
                list += $"{i + 1}. {item.Name} - ${item.Price}\n";
            }
            return(list);
        }