示例#1
0
 //Sort by Name and ID
 public void sortByName() //Using interchange sort
 {
     for (int i = 0; i < magazineList.Count; i++)
     {
         for (int j = i + 1; j < magazineList.Count; j++)
         {
             if (magazineList[i].MagazineName.CompareTo(magazineList[j].MagazineName) > 0)
             {
                 Magazine temp = magazineList[i];
                 magazineList[i] = magazineList[j];
                 magazineList[j] = temp;
             }
         }
     }
 }
示例#2
0
 public void sortByNameAndID() //also using interchange sort
 {
     for (int i = 0; i < magazineList.Count; i++)
     {
         for (int j = i + 1; j < magazineList.Count; j++)
         {
             if (magazineList[i].MagazineName.CompareTo(magazineList[j].MagazineName) > 0) //compare 2 object
             {
                 Magazine temp = magazineList[i];                                          //Swap
                 magazineList[i] = magazineList[j];
                 magazineList[j] = temp;
             }                                                      //if the object are the same
             else if (magazineList[i].MagazineName.CompareTo(magazineList[j].MagazineName) == 0)
             {
                 if (magazineList[i].ID.CompareTo(magazineList[j].ID) < 0) //then compare its ID
                 {
                     Magazine temp2 = magazineList[i];                     //swap their position
                     magazineList[i] = magazineList[j];
                     magazineList[j] = temp2;
                 }
             }
         }
     }
 }
示例#3
0
        static void Main(string[] args)
        {
            Library  library      = new Library();
            Magazine magazineMain = new Magazine();
            Menu     menu         = new Menu("Big Assignment");

            library.addFromFile();
            int   TotalMagazine = library.countTheMagazineNumber();
            float AvgPrize      = library.calculateTheMagazinePrize();

            while (true)
            {
                Console.Clear();
                menu.display();
                int option = menu.GetChoice();
                switch (option)
                {
                case 0:
                {
                    Menu.SayBye();
                    return;
                }

                case 1:
                {
                    Console.WriteLine("HERE IS YOUR LIST.");
                    library.Output();
                    Magazine.PrintFooter(TotalMagazine, AvgPrize);
                    break;
                }

                case 2:
                {
                    Console.WriteLine("HERE IS YOUR SORTED LIST.");
                    library.sortByName();
                    library.Output();
                    break;
                }

                case 3:
                {
                    Console.WriteLine("HERE IS YOUR SORTED LIST.");
                    library.sortByNameAndID();
                    library.Output();
                    break;
                }

                case 4:
                {
                    Console.Write("What is your favorite book: ");
                    string userFavoriteBook = Console.ReadLine();
                    string found            = library.FindUserFavoriteBook(userFavoriteBook);
                    Console.WriteLine("{0}", found);
                    break;
                }

                case 5:
                {
                    Console.WriteLine("Look at the title, cool huh??.");
                    const int    maxProgressBarLength = 60;      //
                    const string progressBarElement   = "█";

                    var title = "";        // empty string for the title , var is implicitly (meaning: khong tuong minh)
                    int loop  = 60;        //Loop 60 times equal to the bar lenght
                    do
                    {
                        loop--;                                  // subtract Loop value
                        title += progressBarElement;             //append bar element to the empty title

                        if (title.Length > maxProgressBarLength) //append until the lenght of the title > 60 then stop title = 60
                        {
                            title = progressBarElement;          // title = 60 words long
                        }

                        Console.Title = title;  //every time adding a bar element into the console title

                        Thread.Sleep(50);       // Control the speed
                    } while (loop != 0);        // end when loop = 0, loop 60 times and it will auto stop (speed milisecond)
                    break;
                }
                }
                //Delay
                Menu.Delay();
            }
        }
示例#4
0
 //Methods
 public void addMagazine(Magazine magazine) //Using object magazine and add magazine into list
 {
     magazineList.Add(magazine);
 }