Lirbo

C# Concert Matrix

Apr 23rd, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.52 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Matrix
  4. {
  5.     class Program
  6.     {
  7.         const int SHOW_NAME = 0;
  8.         const int SHOW_ARTIST = 1;
  9.         const int SHOW_PRICE = 2;
  10.         const int SHOW_TYPE = 3;
  11.         const int SHOW_GENRE = 4;
  12.         static void Main(string[] args)
  13.         {
  14.             string[,] liveShow = new string[0, 5];
  15.             int totalSales = 0;
  16.  
  17.             int option = 0;
  18.             do
  19.             {
  20.                 Console.WriteLine("1. Show all concerts\n2. Show all concerts by Genre Name\n3. Add a new concert\n4. Buy concert ticket\n5. Show total sales\n6. Exit");
  21.                 option = int.Parse(Console.ReadLine());
  22.                 switch(option)
  23.                 {
  24.                     case 1:
  25.                         PrintConcerts(liveShow);
  26.                         break;
  27.  
  28.                     case 2:
  29.                         Console.Write("Enter the name of the genre: ");
  30.                         string genre = Console.ReadLine();
  31.                         bool found = false;
  32.                         for(int i = 0; i < liveShow.GetLength(0); i++)
  33.                         {
  34.                             if (genre == liveShow[i, SHOW_GENRE])
  35.                             {
  36.                                 Console.WriteLine($"[Concert {i + 1}] Name: {liveShow[i, SHOW_NAME]}, Artist: {liveShow[i, SHOW_ARTIST]}, Price: {liveShow[i, SHOW_PRICE]}, Ticket: {liveShow[i, SHOW_TYPE]}, Genre: {liveShow[i, SHOW_GENRE]}");
  37.                                 found = true;
  38.                             }
  39.                         }
  40.                         if (found == false) Console.WriteLine($"No {genre} concerts were found!");
  41.                         break;
  42.  
  43.                     case 3:
  44.                         if(liveShow.GetLength(0) >= 10)
  45.                         {
  46.                             Console.WriteLine("No more slots!");
  47.                         }
  48.                         else
  49.                         {
  50.                             string[] ConcertDetails = new string[5];
  51.                             Console.Write("Please enter the concert's name: ");
  52.                             ConcertDetails[SHOW_NAME] = Console.ReadLine();
  53.                             Console.Write("Please enter the artist's name: ");
  54.                             ConcertDetails[SHOW_ARTIST] = Console.ReadLine();
  55.                             Console.Write("Please enter the ticket's price: ");
  56.                             ConcertDetails[SHOW_PRICE] = Console.ReadLine();
  57.                             Console.Write("Please enter the ticket's type: ");
  58.                             ConcertDetails[SHOW_TYPE] = Console.ReadLine();
  59.                             Console.Write("Please enter the concert's genre: ");
  60.                             ConcertDetails[SHOW_GENRE] = Console.ReadLine();
  61.                             liveShow = ModifiedStringArray(liveShow, 1); // Add +1 slot at rank 0
  62.                             liveShow[liveShow.GetLength(0) - 1, SHOW_NAME] = ConcertDetails[SHOW_NAME];
  63.                             liveShow[liveShow.GetLength(0) - 1, SHOW_ARTIST] = ConcertDetails[SHOW_ARTIST];
  64.                             liveShow[liveShow.GetLength(0) - 1, SHOW_PRICE] = ConcertDetails[SHOW_PRICE];
  65.                             liveShow[liveShow.GetLength(0) - 1, SHOW_TYPE] = ConcertDetails[SHOW_TYPE];
  66.                             liveShow[liveShow.GetLength(0) - 1, SHOW_GENRE] = ConcertDetails[SHOW_GENRE];
  67.                             Console.WriteLine($"Concert #{liveShow.GetLength(0)} \"{ConcertDetails[SHOW_NAME]}\" was successfully added!");
  68.                         }
  69.                         break;
  70.  
  71.                     case 4:
  72.                         PrintConcerts(liveShow);
  73.                         Console.Write("Purchase Ticket: Concert #");
  74.                         int buyTicket = int.Parse(Console.ReadLine());
  75.                         if (buyTicket < 1 || buyTicket > liveShow.GetLength(0))
  76.                             Console.WriteLine("Invalid Concert!");
  77.                         else
  78.                         {
  79.                             Console.WriteLine($"You have purchased the ticket to \"{liveShow[buyTicket-1, SHOW_NAME]}\" for ${liveShow[buyTicket - 1, SHOW_PRICE]}");
  80.                             totalSales += int.Parse(liveShow[buyTicket-1, SHOW_PRICE]);
  81.                             for (int i = 0; i < liveShow.GetLength(1); i++) // Delete show
  82.                                 liveShow[buyTicket-1, i] = "";
  83.                             liveShow = ModifiedStringArray(liveShow, -1); // Sort & remove slot
  84.                         }
  85.                         break;
  86.  
  87.                     case 5:
  88.                         Console.WriteLine($"Total sales: {totalSales}");
  89.                         break;
  90.  
  91.                     case 6:
  92.                         Console.WriteLine("Exiting...");
  93.                         break;
  94.  
  95.                     default:
  96.                         Console.WriteLine("Will ya stop causing troubles?");
  97.                         break;
  98.                 }
  99.                 Console.ReadKey();
  100.                 Console.Clear();
  101.             }
  102.             while (option != 6);
  103.  
  104.         }
  105.  
  106.         static void PrintConcerts(string[,] array)
  107.         {
  108.             if (array.GetLength(0) < 1) Console.WriteLine("No concerts available!");
  109.             else
  110.             {
  111.                 for (int i = 0; i < array.GetLength(0); i++)
  112.                 {
  113.                     Console.WriteLine($"[Concert {i + 1}] Name: {array[i, SHOW_NAME]}, Artist: {array[i, SHOW_ARTIST]}, Price: {array[i, SHOW_PRICE]}, Ticket: {array[i, SHOW_TYPE]}, Genre: {array[i, SHOW_GENRE]}");
  114.                 }
  115.             }
  116.         }
  117.  
  118.         static string[,] ModifiedStringArray(string[,] array, int size)
  119.         {
  120.             string[,] tmpstr = new string[array.GetLength(0) + size, array.GetLength(1)];
  121.             int emptyCount = 0;
  122.             for(int i = 0; i < array.GetLength(0); i++)
  123.             {
  124.                 if(size < 1 && array[i, SHOW_NAME] == "") // empty show name = invalid concert
  125.                 {
  126.                     emptyCount++;
  127.                     continue;
  128.                 }
  129.                 tmpstr[i - emptyCount, SHOW_NAME] = array[i, SHOW_NAME];
  130.                 tmpstr[i - emptyCount, SHOW_ARTIST] = array[i, SHOW_ARTIST];
  131.                 tmpstr[i - emptyCount, SHOW_PRICE] = array[i, SHOW_PRICE];
  132.                 tmpstr[i - emptyCount, SHOW_TYPE] = array[i, SHOW_TYPE];
  133.                 tmpstr[i - emptyCount, SHOW_GENRE] = array[i, SHOW_GENRE];
  134.             }
  135.             return tmpstr;
  136.         }
  137.  
  138.     }
  139. }
  140.  
Add Comment
Please, Sign In to add comment