Advertisement
Katina_

StoreBoxes

Jun 26th, 2019
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. //Class
  6. namespace StoreBoxes
  7. {
  8.     class Box
  9.     {
  10.  
  11.  
  12.         public string SerialNumber { get; set; }
  13.         public string ItemName { get; set; }
  14.         public int ItemQuantity { get; set; }
  15.         public double PriceForBox { get; set; }
  16.         public double TotalPrice { get; set; }
  17.     }
  18. }
  19.  
  20. //Main
  21. namespace StoreBoxes
  22. {
  23.     class Program
  24.     {
  25.         static void Main(string[] args)
  26.         {
  27.             List<Box> itemBoxes = new List<Box>();
  28.             double totalPrice = 0;
  29.                      
  30.             while (true)
  31.             {
  32.                 string command = Console.ReadLine();
  33.                 string[] parts = command.Split();
  34.  
  35.                 if(command == "end")
  36.                 {
  37.                     break;
  38.                 }
  39.  
  40.                 string serialNumber = parts[0];
  41.                 string itemName = parts[1];
  42.                 int itemQuantity = int.Parse(parts[2]);
  43.                 double itemPrice = double.Parse(parts[3]);
  44.  
  45.                 totalPrice =itemPrice * itemQuantity;
  46.  
  47.                 Box box = new Box();
  48.                
  49.                 box.SerialNumber = serialNumber;
  50.                 box.ItemName = itemName;
  51.                 box.ItemQuantity = itemQuantity;
  52.                 box.PriceForBox = itemPrice;
  53.                 box.TotalPrice = itemPrice * itemQuantity;
  54.  
  55.                 itemBoxes.Add(box);
  56.             }
  57.  
  58.            List<Box> sortedBox = itemBoxes.OrderBy(boxes => boxes.TotalPrice).ToList();
  59.             sortedBox.Reverse();
  60.  
  61.             foreach (Box box in sortedBox)
  62.             {
  63.                 Console.WriteLine($"{box.SerialNumber}");
  64.                 Console.WriteLine($"-- {box.ItemName} - ${box.PriceForBox:F2}: {box.ItemQuantity}");
  65.                 Console.WriteLine($"-- ${box.TotalPrice:F2}");
  66.                
  67.             }          
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement