Advertisement
YORDAN2347

StoreBoxes

Jan 30th, 2021
746
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _07._StoreBoxes
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string input = Console.ReadLine();
  11.  
  12.             List<Box> boxes = new List<Box>();
  13.  
  14.             while (input != "end")
  15.             {
  16.                 string[] tokens = input.Split();
  17.  
  18.                 Item item = new Item(tokens[1], //Item Name
  19.                     decimal.Parse(tokens[3])); //ItemPrice
  20.  
  21.                 Box box = new Box(tokens[0], //Serial Number
  22.                     item, //Item Name , ItemPrice
  23.                     int.Parse(tokens[2])); //Item Quantity
  24.  
  25.                 boxes.Add(box);
  26.  
  27.                 input = Console.ReadLine();
  28.             }
  29.  
  30.             List<Box> sortedBoxes = SortBoxes(boxes);
  31.  
  32.             foreach (var box in boxes)
  33.             {
  34.                 Console.WriteLine($"{box.SerialNumber}");
  35.                 Console.WriteLine($"-- {box.Item.Name} – " +
  36.                     $"${box.Item.Price}: " +
  37.                     $"{box.ItemQuantity}");
  38.                 Console.WriteLine($"{box.PriceForBox}");
  39.             }    
  40.         }
  41.  
  42.         private static List<Box> SortBoxes(List<Box> boxes)
  43.         {
  44.             List<Box> sortedBoxes = new List<Box>();
  45.  
  46.             for (int i = 0; i < boxes.Count; i++)
  47.             {
  48.  
  49.             }
  50.  
  51.             return sortedBoxes;
  52.         }
  53.     }
  54.  
  55.     class Item
  56.     {
  57.         public Item(string name, decimal price)
  58.         {
  59.             Name = name;
  60.             Price = price;
  61.         }
  62.         public string Name { get; set; }
  63.         public decimal Price { get; set; }
  64.     }
  65.  
  66.     class Box
  67.     {
  68.         public Box(string serialNumber,
  69.             Item item,
  70.             int itemQuantity)
  71.            
  72.         {
  73.             SerialNumber = serialNumber;
  74.             Item = item;
  75.             ItemQuantity = itemQuantity;
  76.             PriceForBox = item.Price * ItemQuantity;
  77.         }
  78.         public string SerialNumber { get; set; }
  79.         public Item Item { get; set; }
  80.         public int ItemQuantity { get; set; }
  81.         public decimal PriceForBox { get; set; }
  82.  
  83.     }
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement