Advertisement
silvana1303

boxes

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