Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- namespace Directory
- {
- class Showroom
- {
- public readonly int income;
- private string name, classification;
- public readonly DateTime openingDate;
- public Showroom()
- {
- Console.Write("\nInput the showroom's name: ");
- name = Console.ReadLine();
- Console.Write("\nInput the classification: ");
- classification = Console.ReadLine();
- Console.Write("\nInput opening date (dd.MM.yyyy): ");
- openingDate = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", null);
- Console.Write("\nInput the income: ");
- income = Convert.ToInt32(Console.ReadLine());
- Console.Clear();
- }
- public void PrintData()
- {
- Console.WriteLine($"Name: {name}");
- Console.WriteLine($"Classification: {classification}");
- Console.WriteLine($"Opening date: {openingDate.ToString().Replace(" 0:00:00", "")}");
- Console.WriteLine($"Income: {income}\n");
- }
- }
- class Auto
- {
- private string brand, model, slogan, steeringPosition;
- private int enginePower, length, width, seatsNumber;
- private DateTime saleDate, guaranteeExpires;
- public Auto()
- {
- Console.Write("\nInput auto brand: ");
- brand = Console.ReadLine();
- Console.Write("\nInput the model name: ");
- model = Console.ReadLine();
- Console.Write("\nInput the slogan: ");
- slogan = Console.ReadLine();
- Console.Write("\nInput the engine power: ");
- enginePower = Convert.ToInt32(Console.ReadLine());
- Console.Write("\nInput length: ");
- length = Convert.ToInt32(Console.ReadLine());
- Console.Write("\nInput width: ");
- width = Convert.ToInt32(Console.ReadLine());
- Console.Write("\nInput steering position: ");
- steeringPosition = Console.ReadLine();
- Console.Write("\nInput the number of seats: ");
- seatsNumber = Convert.ToInt32(Console.ReadLine());
- Console.Write("\nInput sale date (dd.MM.yyyy): ");
- saleDate = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", null);
- Console.Write("\nInput the guarantee expiration date (dd.MM.yyyy): ");
- guaranteeExpires = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", null);
- Console.Clear();
- }
- }
- class Employee
- {
- private int ID, discount;
- private string name, surname, post, homeAddress;
- private DateTime birthDate, recruitmentDate;
- public Employee()
- {
- Console.Write("\nInput ID: ");
- ID = Convert.ToInt32(Console.ReadLine());
- Console.Write("\nInput first name: ");
- name = Console.ReadLine();
- Console.Write("\nInput last name: ");
- surname = Console.ReadLine();
- Console.Write("\nInput post: ");
- post = Console.ReadLine();
- Console.Write("\nInput discount value (in percents): ");
- discount = Convert.ToInt32(Console.ReadLine());
- Console.Write("\nInput home address: ");
- homeAddress = Console.ReadLine();
- Console.Write("\nInput birth date (dd.MM.yyyy): ");
- birthDate = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", null);
- Console.Write("\nInput recruitment date (dd.MM.yyyy): ");
- recruitmentDate = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", null);
- Console.Clear();
- }
- }
- class Program
- {
- private static List<Showroom> showrooms = new List<Showroom>();
- private static List<Auto> autos = new List<Auto>();
- private static List<Employee> employees = new List<Employee>();
- static void Main(string[] args)
- {
- Console.Title = "Directory (task #43)";
- while (true)
- {
- CallInterface();
- switch (Console.ReadLine())
- {
- case "1":
- showrooms.Add(new Showroom());
- break;
- case "2":
- autos.Add(new Auto());
- break;
- case "3":
- employees.Add(new Employee());
- break;
- case "4":
- if (showrooms.Count > 0)
- {
- for (int i = 0, j = 1; i < showrooms.Count; i++)
- {
- if (showrooms[i].openingDate.DayOfWeek == DayOfWeek.Monday)
- {
- if (j == 1)
- {
- Console.WriteLine("{0, 50}", "List of showrooms opened on Monday:");
- }
- Console.WriteLine($"-----{j++}-----");
- showrooms[i].PrintData();
- }
- }
- Console.Write("\nPress any key to continue...");
- Console.ReadKey();
- Console.Clear();
- }
- else
- {
- Console.Clear();
- Console.WriteLine("Error: There are no showrooms in the database!");
- }
- break;
- case "5":
- if (showrooms.Count > 0)
- {
- int averageIncome = 0;
- for (int i = 0; i < showrooms.Count; i++)
- {
- averageIncome += showrooms[i].income;
- }
- averageIncome /= showrooms.Count;
- Console.WriteLine($"The average income is {averageIncome}");
- Console.Write("\nPress any key to continue...");
- Console.ReadKey();
- Console.Clear();
- }
- else
- {
- Console.Clear();
- Console.WriteLine("Error: There are no showrooms in the database!");
- }
- break;
- case "quit":
- Environment.Exit(0);
- break;
- default:
- Console.Clear();
- Console.WriteLine("Error: Incorrect command!");
- break;
- }
- }
- }
- static void CallInterface()
- {
- 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" };
- void DrawBorder()
- {
- for (int i = 0; i < Console.WindowWidth; i++)
- {
- Console.Write("=");
- }
- }
- void NewLine()
- {
- Console.Write("|");
- for (int i = 0; i < Console.WindowWidth - 2; i++)
- {
- Console.Write(" ");
- }
- Console.Write("|");
- }
- void AddActions(string[] actions)
- {
- for (int i = 0; i < actions.Length; i++)
- {
- Console.Write($"| {actions[i]}");
- for (int j = 0; j < Console.WindowWidth - actions[i].Length - 3; j++)
- {
- Console.Write(" ");
- }
- Console.Write("|");
- NewLine();
- }
- }
- DrawBorder();
- NewLine();
- AddActions(allActions);
- DrawBorder();
- Console.Write("{0, 122}", "quit - exit from the interface\n> ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement