Advertisement
ARASKES

Stores

Dec 18th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Stores
  5. {
  6.     enum Classe
  7.     {
  8.         ECONOM, STANDARD, PREMIUM
  9.     }
  10.  
  11.     enum LoyaltyProgram
  12.     {
  13.         BASIC, SILVER, GOLDEN
  14.     }
  15.  
  16.     class Product
  17.     {
  18.         public List<string> properties = new List<string>();
  19.         public readonly string name, type;
  20.         public readonly int tax;
  21.         public readonly int[,] prices = new int[2, 2];
  22.         public readonly Classe classe;
  23.  
  24.         public Product()
  25.         {
  26.             Console.Write("Input the product's name: ");
  27.             name = Console.ReadLine();
  28.  
  29.             Console.Write("Input the type: ");
  30.             type = Console.ReadLine();
  31.  
  32.             Console.Write("Input the tax (in %): ");
  33.             tax = Convert.ToInt32(Console.ReadLine());
  34.  
  35.             Console.Write("Input the retail client price: ");
  36.             prices[0, 0] = Convert.ToInt32(Console.ReadLine());
  37.  
  38.             Console.Write("Input the retail corporative price: ");
  39.             prices[0, 1] = Convert.ToInt32(Console.ReadLine());
  40.  
  41.             Console.Write("Input the wholesale client price: ");
  42.             prices[1, 0] = Convert.ToInt32(Console.ReadLine());
  43.  
  44.             Console.Write("Input the wholesale corporative price: ");
  45.             prices[1, 1] = Convert.ToInt32(Console.ReadLine());
  46.  
  47.             bool flag = true;
  48.             while (flag)
  49.             {
  50.                 Console.Write("Add some properties (add - to add a property\tstop - to stop the input):\n> ");
  51.                 switch (Console.ReadLine())
  52.                 {
  53.                     case "add":
  54.                         properties.Add(Console.ReadLine());
  55.                         Console.Clear();
  56.                         break;
  57.                     case "stop":
  58.                         flag = false;
  59.                         Console.Clear();
  60.                         break;
  61.                     default:
  62.                         Console.Clear();
  63.                         Console.WriteLine("Error: there is no such action!");
  64.                         break;
  65.                 }
  66.             }
  67.  
  68.             flag = true;
  69.             while (flag)
  70.             {
  71.                 Console.Write("Input the class (1. Econom\t2. Standard\t3. Premium):\n> ");
  72.                 switch (Console.ReadLine())
  73.                 {
  74.                     case "1":
  75.                         classe = Classe.ECONOM;
  76.                         flag = false;
  77.                         break;
  78.                     case "2":
  79.                         classe = Classe.STANDARD;
  80.                         flag = false;
  81.                         break;
  82.                     case "3":
  83.                         classe = Classe.PREMIUM;
  84.                         flag = false;
  85.                         break;
  86.                     default:
  87.                         Console.Clear();
  88.                         Console.WriteLine("Error: there is no such class!");
  89.                         break;
  90.                 }
  91.             }
  92.         }
  93.     }
  94.  
  95.     class Stand
  96.     {
  97.         public List<Product> goods = new List<Product>();
  98.  
  99.         public Stand()
  100.         {
  101.             bool flag = true;
  102.             while (flag)
  103.             {
  104.                 Console.Write("Add some goods (add - to add a product\tstop - to stop the input):\n> ");
  105.                 switch (Console.ReadLine())
  106.                 {
  107.                     case "add":
  108.                         goods.Add(new Product());
  109.                         Console.Clear();
  110.                         break;
  111.                     case "stop":
  112.                         flag = false;
  113.                         Console.Clear();
  114.                         break;
  115.                     default:
  116.                         Console.Clear();
  117.                         Console.WriteLine("Error: there is no such action!");
  118.                         break;
  119.                 }
  120.             }
  121.         }
  122.     }
  123.  
  124.     class Store
  125.     {
  126.         private string name;
  127.         private LoyaltyProgram loyalty;
  128.         private static List<Stand> stands = new List<Stand>();
  129.  
  130.         public Store()
  131.         {
  132.             Console.Write("Input the name: ");
  133.             name = Console.ReadLine();
  134.  
  135.             bool flag = true;
  136.             while (flag)
  137.             {
  138.                 Console.Write("Input the loyalty program (1. Basic\t2. Silver\t3. Golden):\n> ");
  139.                 switch (Console.ReadLine())
  140.                 {
  141.                     case "1":
  142.                         loyalty = LoyaltyProgram.BASIC;
  143.                         flag = false;
  144.                         break;
  145.                     case "2":
  146.                         loyalty = LoyaltyProgram.SILVER;
  147.                         flag = false;
  148.                         break;
  149.                     case "3":
  150.                         loyalty = LoyaltyProgram.GOLDEN;
  151.                         flag = false;
  152.                         break;
  153.                     default:
  154.                         Console.Clear();
  155.                         Console.WriteLine("Error: there is no such loyalty program!");
  156.                         break;
  157.                 }
  158.             }
  159.  
  160.             flag = true;
  161.             while (flag)
  162.             {
  163.                 Console.Write("Add some stands (add - to add a stand\tstop - to stop the input):\n> ");
  164.                 switch (Console.ReadLine())
  165.                 {
  166.                     case "add":
  167.                         stands.Add(new Stand());
  168.                         Console.Clear();
  169.                         break;
  170.                     case "stop":
  171.                         flag = false;
  172.                         Console.Clear();
  173.                         break;
  174.                     default:
  175.                         Console.Clear();
  176.                         Console.WriteLine("Error: there is no such action!");
  177.                         break;
  178.                 }
  179.             }
  180.         }
  181.  
  182.         public void ShowInfo()
  183.         {
  184.             int[,,] discount = new int[3, 2, 2];
  185.             discount[0, 0, 0] = discount[2, 0, 1] = discount[1, 1, 1] = 5;
  186.             discount[1, 0, 0] = discount[1, 1, 0] = 7;
  187.             discount[0, 1, 0] = discount[2, 1, 1] = 6;
  188.             discount[0, 0, 1] = 2;
  189.             discount[0, 1, 1] = 3;
  190.             discount[1, 0, 1] = 4;
  191.             discount[2, 0, 0] = 10;
  192.             discount[2, 1, 0] = 11;
  193.             int[] loyaltyDiscount = { 5, 10, 15 }, wholesaleDiscount = { 2, 3, 5 };
  194.  
  195.             Console.WriteLine($"Store \"{name}\":");
  196.             Console.Write("\tLoyalty program type: ");
  197.             switch (loyalty)
  198.             {
  199.                 case LoyaltyProgram.BASIC:
  200.                     Console.WriteLine("Basic");
  201.                     break;
  202.                 case LoyaltyProgram.SILVER:
  203.                     Console.WriteLine("Silver");
  204.                     break;
  205.                 case LoyaltyProgram.GOLDEN:
  206.                     Console.WriteLine("Golden");
  207.                     break;
  208.             }
  209.             for (int i = 0; i < stands.Count; i++)
  210.             {
  211.                 Console.WriteLine($"\tStand {i + 1}:");
  212.                 for (int j = 0; j < stands[i].goods.Count; j++)
  213.                 {
  214.                     Console.WriteLine($"\t\tProduct \"{stands[i].goods[j].name}\":");
  215.                     Console.WriteLine($"\t\t\tType: \"{stands[i].goods[j].type}\"");
  216.                     Console.Write($"\t\t\tClass: ");
  217.                     switch(stands[i].goods[j].classe)
  218.                     {
  219.                         case Classe.ECONOM:
  220.                             Console.WriteLine("Econom");
  221.                             break;
  222.                         case Classe.STANDARD:
  223.                             Console.WriteLine("Standard");
  224.                             break;
  225.                         case Classe.PREMIUM:
  226.                             Console.WriteLine("Premium");
  227.                             break;
  228.                     }
  229.                     Console.WriteLine("\t\t\tProperties:");
  230.                     for (int k = 0; k < stands[i].goods[j].properties.Count; k++)
  231.                     {
  232.                         Console.WriteLine($"\t\t\t\tProperty {k + 1}: {stands[i].goods[j].properties[k]}");
  233.                     }
  234.                     Console.WriteLine("\t\t\tPrice:");
  235.                     Console.WriteLine("\t\t\t\tRetail:");
  236.                     Console.WriteLine($"\t\t\t\t\tClient: {stands[i].goods[j].prices[0, 0] * (100 + stands[i].goods[j].tax) / 100 * (100 - discount[(int)stands[i].goods[j].classe, 0, 0]) / 100 * (100 - loyaltyDiscount[(int)loyalty]) / 100}");
  237.  
  238.                     Console.WriteLine($"\t\t\t\t\tCorporative: {stands[i].goods[j].prices[0, 1] * (100 + stands[i].goods[j].tax) / 100 * (100 - discount[(int)stands[i].goods[j].classe, 0, 1]) / 100 * (100 - loyaltyDiscount[(int)loyalty]) / 100}");
  239.  
  240.                     Console.WriteLine("\t\t\t\tWholesale:");
  241.                     Console.WriteLine($"\t\t\t\t\tClient: ");
  242.                     for (int k = 0; k < 3; k++)
  243.                     {
  244.                         Console.WriteLine($"\t\t\t\t\t\t{Math.Pow(10, k + 1)}: {stands[i].goods[j].prices[1, 0] * (100 + stands[i].goods[j].tax) / 100 * (100 - discount[(int)stands[i].goods[j].classe, 1, 0]) / 100 * (100 - loyaltyDiscount[(int)loyalty]) / 100 * (100 - wholesaleDiscount[k]) / 100}");
  245.                     }
  246.  
  247.                     Console.WriteLine($"\t\t\t\t\tCorporative: ");
  248.                     for (int k = 0; k < 3; k++)
  249.                     {
  250.                         Console.WriteLine($"\t\t\t\t\t\t{Math.Pow(10, k + 1)}: {stands[i].goods[j].prices[1, 1] * (100 + stands[i].goods[j].tax) / 100 * (100 - discount[(int)stands[i].goods[j].classe, 1, 1]) / 100 * (100 - loyaltyDiscount[(int)loyalty]) / 100 * (100 - wholesaleDiscount[k]) / 100}");
  251.                     }
  252.                 }
  253.             }
  254.             Console.WriteLine("Press any key to continue...");
  255.             Console.ReadKey();
  256.         }
  257.     }
  258.  
  259.     class Program
  260.     {
  261.         private static List<Store> stores = new List<Store>();
  262.  
  263.         static void Main(string[] args)
  264.         {
  265.             Console.Title = "Stores";
  266.             while (true)
  267.             {
  268.                 CallInterface();
  269.                 switch (Console.ReadLine())
  270.                 {
  271.                     case "1":
  272.                         stores.Add(new Store());
  273.                         Console.Clear();
  274.                         break;
  275.                     case "2":
  276.                         if (stores.Count > 0)
  277.                         {
  278.                             for (int i = 0; i < stores.Count; i++)
  279.                             {
  280.                                 stores[i].ShowInfo();
  281.                             }
  282.                             Console.Clear();
  283.                         }
  284.                         else
  285.                         {
  286.                             Console.Clear();
  287.                             Console.WriteLine("Error: There is no data!");
  288.                         }
  289.                         break;
  290.                     case "quit":
  291.                         Environment.Exit(0);
  292.                         break;
  293.                     default:
  294.                         Console.Clear();
  295.                         Console.WriteLine("Error: Unknown command!");
  296.                         break;
  297.                 }
  298.             }
  299.         }
  300.  
  301.         static void CallInterface()
  302.         {
  303.             string[] allActions = { "1. Add a store", "2. Show all the info" };
  304.             void DrawBorder()
  305.             {
  306.                 for (int i = 0; i < Console.WindowWidth; i++)
  307.                 {
  308.                     Console.Write("=");
  309.                 }
  310.             }
  311.             void NewLine()
  312.             {
  313.                 Console.Write("|");
  314.                 for (int i = 0; i < Console.WindowWidth - 2; i++)
  315.                 {
  316.                     Console.Write(" ");
  317.                 }
  318.                 Console.Write("|");
  319.             }
  320.             void AddActions(string[] actions)
  321.             {
  322.                 for (int i = 0; i < actions.Length; i++)
  323.                 {
  324.                     Console.Write($"| {actions[i]}");
  325.                     for (int j = 0; j < Console.WindowWidth - actions[i].Length - 3; j++)
  326.                     {
  327.                         Console.Write(" ");
  328.                     }
  329.                     Console.Write("|");
  330.                     NewLine();
  331.                 }
  332.             }
  333.  
  334.             DrawBorder();
  335.             NewLine();
  336.             AddActions(allActions);
  337.             DrawBorder();
  338.             Console.Write("{0, 82}", "quit - exit from the interface\n> ");
  339.         }
  340.     }
  341. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement