Advertisement
nikolayneykov

Untitled

Mar 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         List<Box> boxes = new List<Box>();
  10.         string input = string.Empty;
  11.  
  12.         while ((input=Console.ReadLine())!="end")
  13.         {
  14.             string[] tokens = input.Split(' ');
  15.             string serialNumber = tokens[0];
  16.             string itemName = tokens[1];
  17.             int itemQuantity = int.Parse(tokens[2]);
  18.             decimal itemPrice = decimal.Parse(tokens[3]);
  19.             boxes.Add(new Box(serialNumber, itemName, itemQuantity, itemPrice));
  20.         }
  21.  
  22.         boxes.OrderByDescending(b=>b.GetBoxPrice()).ToList().ForEach(b => Console.WriteLine(b));
  23.     }
  24. }
  25.  
  26. class Box
  27. {
  28.     public Box(string serialNumber, string itemName,int itemQuantity,decimal itemPrice)
  29.     {
  30.         this.SerialNumber = serialNumber;
  31.         this.ItemName = itemName;
  32.         this.ItemQuantity = itemQuantity;
  33.         this.ItemPrice = itemPrice;
  34.     }
  35.  
  36.     public string SerialNumber { get; set; }
  37.     public string ItemName { get; set; }
  38.     public int ItemQuantity { get; set; }
  39.     public decimal ItemPrice { get; set; }
  40.  
  41.     public decimal GetBoxPrice()
  42.     {
  43.         return this.ItemPrice * this.ItemQuantity;
  44.     }
  45.  
  46.     public override string ToString()
  47.     {
  48.         return this.SerialNumber +
  49.             Environment.NewLine +
  50.             $"-- {this.ItemName} - ${this.ItemPrice:F2}: {this.ItemQuantity}"+
  51.         Environment.NewLine +
  52.             $"-- ${this.GetBoxPrice():F2}";
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement