anizko

7. Store Boxes

Jun 22nd, 2019
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _07._Store_Boxes
  6. {
  7.  
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<Box> boxes = new List<Box>();
  13.  
  14.             while (true)
  15.             {
  16.                 string[] informationForBoxes = Console.ReadLine().Split().ToArray();
  17.  
  18.                 if (informationForBoxes[0] == "end")
  19.                 {
  20.  
  21.                     List<Box> result = boxes.OrderByDescending(x => x.ItemPrice).ToList();
  22.  
  23.                     foreach (var box in result)
  24.                     {
  25.                         Console.WriteLine(box.SerialNumber);
  26.                         Console.WriteLine($"-- {box.ItemName.Name} - ${box.ItemName.Price:f2}: {box.ItemQuantity}");
  27.                         Console.WriteLine($"-- ${box.PriceOfBox:f2}");
  28.                     }
  29.  
  30.                 }
  31.                 else
  32.                 {
  33.                     boxes.Add(new Box(informationForBoxes));
  34.                 }
  35.             }
  36.         }
  37.     }
  38. class Item
  39.     {
  40.         public string Name { get; set; }
  41.         public double Price { get; set; }
  42.  
  43.         public Item (string itemName,  double ItemPrice)
  44.         {
  45.             this.Name = itemName;
  46.             this.Price = ItemPrice;
  47.         }
  48.     }
  49. class Box
  50.     {
  51.         public int SerialNumber { get; set; }
  52.         public Item ItemName { get; set; }
  53.         public int ItemQuantity { get; set; }
  54.         public double ItemPrice { get; set; }
  55.         public double PriceOfBox { get; set; }
  56.  
  57.         public Box(string []informationForBoxes)
  58.         {
  59.             SerialNumber = int.Parse(informationForBoxes[0]);
  60.             ItemQuantity = int.Parse(informationForBoxes[2]);
  61.             ItemPrice = double.Parse(informationForBoxes[3]);
  62.          
  63.             PriceOfBox = ItemQuantity * ItemPrice;
  64.  
  65.             string itemName = informationForBoxes[1];
  66.  
  67.             ItemName = new Item(itemName, ItemPrice);
  68.         }
  69.  
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment