TheBulgarianWolf

Store Boxes

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