Advertisement
alexbancheva

Problem_7._Store_Boxes_Лаб_Classes

Jul 13th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Problem_7._Store_Boxes_Лаб_Classes
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.  
  13.             List<Box> boxes = new List<Box>();
  14.  
  15.             while (input != "end")
  16.             {
  17.                 string[] data = input.Split(" ").ToArray();
  18.  
  19.                 int serialNumber = int.Parse(data[0]);
  20.                 string itemName = data[1];
  21.                 int itemQuantity = int.Parse(data[2]);
  22.                 double itemPrice = double.Parse(data[3]);
  23.  
  24.                 Box box = new Box();
  25.  
  26.                 box.SerialNumber = serialNumber;
  27.                 box.Item.Name = itemName;
  28.                 box.ItemQuantity = itemQuantity;
  29.                 box.Item.Price = itemPrice;
  30.                 box.SetThePrice();
  31.  
  32.                 boxes.Add(box);
  33.  
  34.                 input = Console.ReadLine();
  35.             }
  36.  
  37.             List<Box> filtredBoxes = boxes.OrderByDescending(b => b.PriceForOneBox).ToList();
  38.  
  39.             foreach (Box item in filtredBoxes)
  40.             {
  41.                 Console.WriteLine($"{item.SerialNumber}");
  42.                 Console.WriteLine($"-- {item.Item.Name} - ${item.Item.Price}: {item.ItemQuantity}");
  43.                 Console.WriteLine($"-- ${item.PriceForOneBox:f2}");
  44.             }
  45.         }
  46.     }
  47.  
  48.    public class Item
  49.     {
  50.  
  51.         public string Name { get; set; }
  52.  
  53.         public double Price { get; set; }
  54.     }
  55.  
  56.   public  class Box
  57.     {
  58.         public Box()
  59.         {
  60.  
  61.             Item = new Item();
  62.        
  63.         }
  64.         public int SerialNumber { get; set; }
  65.  
  66.         public Item Item { get; set; }
  67.  
  68.         public int ItemQuantity { get; set; }
  69.  
  70.         public double PriceForOneBox { get; set; }
  71.  
  72.         public void SetThePrice()
  73.         {
  74.             this.PriceForOneBox = ItemQuantity * Item.Price;
  75.         }
  76.  
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement