Advertisement
nikolayneykov

Untitled

Mar 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _07StoreBoxes
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<Box> boxList = new List<Box>();
  12.  
  13.             string input = string.Empty;
  14.             while ((input = Console.ReadLine()) != "end")
  15.             {
  16.                 string[] data = input.Split(" ");
  17.                 string serialNumber = data[0];
  18.                 string itemName = data[1];
  19.                 int itemQuantity = int.Parse(data[2]);
  20.                 decimal itemPrice = decimal.Parse(data[3]);
  21.  
  22.                 decimal priceBox = itemQuantity * itemPrice;
  23.  
  24.                 Box currentBox = new Box()
  25.                 {
  26.                     SerialNumber = serialNumber,
  27.                     ItemQuantity = itemQuantity,
  28.                     PriceBox = priceBox
  29.                 };
  30.  
  31.                 currentBox.Item.Name = itemName;
  32.                 currentBox.Item.Price = itemPrice;
  33.  
  34.                 boxList.Add(currentBox);
  35.             }
  36.           boxList =  boxList.OrderByDescending(x => x.PriceBox).ToList();
  37.  
  38.  
  39.             foreach (var box in boxList)
  40.             {
  41.                 Console.WriteLine($"{box.SerialNumber}");
  42.                 Console.WriteLine($"-- {box.Item.Name} - ${box.Item.Price:F2}: {box.ItemQuantity}");
  43.                 Console.WriteLine($"-- ${box.PriceBox:F2}");
  44.             }
  45.         }
  46.     }
  47.  
  48.     class Item
  49.     {
  50.         public string Name { get; set; }
  51.         public decimal Price { get; set; }
  52.     }
  53.  
  54.     class Box
  55.     {
  56.         public Box()
  57.         {
  58.             Item = new Item();
  59.         }
  60.  
  61.         public string SerialNumber { get; set; }
  62.         public Item Item { get; set; }
  63.         public int ItemQuantity { get; set; }
  64.         public decimal PriceBox { get; set; }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement