Advertisement
ARASKES

Directory

Nov 20th, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4.  
  5. namespace Directory
  6. {
  7.     class Showroom
  8.     {
  9.         public readonly int income;
  10.         private string name, classification;
  11.         public readonly DateTime openingDate;
  12.         public Showroom()
  13.         {
  14.             Console.Write("\nInput the showroom's name: ");
  15.             name = Console.ReadLine();
  16.  
  17.             Console.Write("\nInput the classification: ");
  18.             classification = Console.ReadLine();
  19.  
  20.             Console.Write("\nInput opening date (dd.MM.yyyy): ");
  21.             openingDate = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", null);
  22.  
  23.             Console.Write("\nInput the income: ");
  24.             income = Convert.ToInt32(Console.ReadLine());
  25.  
  26.             Console.Clear();
  27.         }
  28.         public void PrintData()
  29.         {
  30.             Console.WriteLine($"Name: {name}");
  31.             Console.WriteLine($"Classification: {classification}");
  32.             Console.WriteLine($"Opening date: {openingDate.ToString().Replace(" 0:00:00", "")}");
  33.             Console.WriteLine($"Income: {income}\n");
  34.         }
  35.     }
  36.  
  37.     class Auto
  38.     {
  39.         private string brand, model, slogan, steeringPosition;
  40.         private int enginePower, length, width, seatsNumber;
  41.         private DateTime saleDate, guaranteeExpires;
  42.         public Auto()
  43.         {
  44.             Console.Write("\nInput auto brand: ");
  45.             brand = Console.ReadLine();
  46.  
  47.             Console.Write("\nInput the model name: ");
  48.             model = Console.ReadLine();
  49.  
  50.             Console.Write("\nInput the slogan: ");
  51.             slogan = Console.ReadLine();
  52.  
  53.             Console.Write("\nInput the engine power: ");
  54.             enginePower = Convert.ToInt32(Console.ReadLine());
  55.  
  56.             Console.Write("\nInput length: ");
  57.             length = Convert.ToInt32(Console.ReadLine());
  58.  
  59.             Console.Write("\nInput width: ");
  60.             width = Convert.ToInt32(Console.ReadLine());
  61.  
  62.             Console.Write("\nInput steering position: ");
  63.             steeringPosition = Console.ReadLine();
  64.  
  65.             Console.Write("\nInput the number of seats: ");
  66.             seatsNumber = Convert.ToInt32(Console.ReadLine());
  67.  
  68.             Console.Write("\nInput sale date (dd.MM.yyyy): ");
  69.             saleDate = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", null);
  70.  
  71.             Console.Write("\nInput the guarantee expiration date (dd.MM.yyyy): ");
  72.             guaranteeExpires = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", null);
  73.  
  74.             Console.Clear();
  75.         }
  76.     }
  77.  
  78.     class Employee
  79.     {
  80.         private int ID, discount;
  81.         private string name, surname, post, homeAddress;
  82.         private DateTime birthDate, recruitmentDate;
  83.         public Employee()
  84.         {
  85.             Console.Write("\nInput ID: ");
  86.             ID = Convert.ToInt32(Console.ReadLine());
  87.  
  88.             Console.Write("\nInput first name: ");
  89.             name = Console.ReadLine();
  90.  
  91.             Console.Write("\nInput last name: ");
  92.             surname = Console.ReadLine();
  93.  
  94.             Console.Write("\nInput post: ");
  95.             post = Console.ReadLine();
  96.  
  97.             Console.Write("\nInput discount value (in percents): ");
  98.             discount = Convert.ToInt32(Console.ReadLine());
  99.  
  100.             Console.Write("\nInput home address: ");
  101.             homeAddress = Console.ReadLine();
  102.  
  103.             Console.Write("\nInput birth date (dd.MM.yyyy): ");
  104.             birthDate = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", null);
  105.  
  106.             Console.Write("\nInput recruitment date (dd.MM.yyyy): ");
  107.             recruitmentDate = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", null);
  108.  
  109.             Console.Clear();
  110.         }
  111.     }
  112.  
  113.     class Program
  114.     {
  115.         private static List<Showroom> showrooms = new List<Showroom>();
  116.         private static List<Auto> autos = new List<Auto>();
  117.         private static List<Employee> employees = new List<Employee>();
  118.  
  119.         static void Main(string[] args)
  120.         {
  121.             Console.Title = "Directory (task #43)";
  122.             while (true)
  123.             {
  124.                 CallInterface();
  125.                 switch (Console.ReadLine())
  126.                 {
  127.                     case "1":
  128.                         showrooms.Add(new Showroom());
  129.                         break;
  130.                     case "2":
  131.                         autos.Add(new Auto());
  132.                         break;
  133.                     case "3":
  134.                         employees.Add(new Employee());
  135.                         break;
  136.                     case "4":
  137.                         if (showrooms.Count > 0)
  138.                         {
  139.                             for (int i = 0, j = 1; i < showrooms.Count; i++)
  140.                             {
  141.                                 if (showrooms[i].openingDate.DayOfWeek == DayOfWeek.Monday)
  142.                                 {
  143.                                     if (j == 1)
  144.                                     {
  145.                                         Console.WriteLine("{0, 50}", "List of showrooms opened on Monday:");
  146.                                     }
  147.                                     Console.WriteLine($"-----{j++}-----");
  148.                                     showrooms[i].PrintData();
  149.                                 }
  150.                             }
  151.                             Console.Write("\nPress any key to continue...");
  152.                             Console.ReadKey();
  153.                             Console.Clear();
  154.                         }
  155.                         else
  156.                         {
  157.                             Console.Clear();
  158.                             Console.WriteLine("Error: There are no showrooms in the database!");
  159.                         }
  160.                         break;
  161.                     case "5":
  162.                         if (showrooms.Count > 0)
  163.                         {
  164.                             int averageIncome = 0;
  165.                             for (int i = 0; i < showrooms.Count; i++)
  166.                             {
  167.                                 averageIncome += showrooms[i].income;
  168.                             }
  169.                             averageIncome /= showrooms.Count;
  170.                             Console.WriteLine($"The average income is {averageIncome}");
  171.                             Console.Write("\nPress any key to continue...");
  172.                             Console.ReadKey();
  173.                             Console.Clear();
  174.                         }
  175.                         else
  176.                         {
  177.                             Console.Clear();
  178.                             Console.WriteLine("Error: There are no showrooms in the database!");
  179.                         }
  180.                         break;
  181.                     case "quit":
  182.                         Environment.Exit(0);
  183.                         break;
  184.                     default:
  185.                         Console.Clear();
  186.                         Console.WriteLine("Error: Incorrect command!");
  187.                         break;
  188.                 }
  189.             }
  190.         }
  191.  
  192.         static void CallInterface()
  193.         {
  194.             string[] allActions = { "1. Add a new showroom", "2. Add a new auto", "3. Add a new employee", "4. Show list of showrooms opened on Monday", "5. Show average showrooms' income" };
  195.             void DrawBorder()
  196.             {
  197.                 for (int i = 0; i < Console.WindowWidth; i++)
  198.                 {
  199.                     Console.Write("=");
  200.                 }
  201.             }
  202.             void NewLine()
  203.             {
  204.                 Console.Write("|");
  205.                 for (int i = 0; i < Console.WindowWidth - 2; i++)
  206.                 {
  207.                     Console.Write(" ");
  208.                 }
  209.                 Console.Write("|");
  210.             }
  211.             void AddActions(string[] actions)
  212.             {
  213.                 for (int i = 0; i < actions.Length; i++)
  214.                 {
  215.                     Console.Write($"| {actions[i]}");
  216.                     for (int j = 0; j < Console.WindowWidth - actions[i].Length - 3; j++)
  217.                     {
  218.                         Console.Write(" ");
  219.                     }
  220.                     Console.Write("|");
  221.                     NewLine();
  222.                 }
  223.             }
  224.  
  225.             DrawBorder();
  226.             NewLine();
  227.             AddActions(allActions);
  228.             DrawBorder();
  229.             Console.Write("{0, 122}", "quit - exit from the interface\n> ");
  230.         }
  231.     }
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement