Advertisement
nikolapetkov824

StoreBoxes

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