Advertisement
gospod1978

Object and Class/Store Box

Oct 24th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Globalization;
  6.  
  7.  
  8. namespace Box
  9. {
  10.     class Box
  11.     {
  12.  
  13.  
  14.         public string Name { get; set; }
  15.         public decimal Price { get; set; }
  16.         public string SerialNumber { get; set; }
  17.         public int Quantity { get; set; }
  18.         public decimal BoxPrice { get; set; }
  19.  
  20.         public Box(string name, decimal price, string serialNumber, int quantity, decimal boxPrice)
  21.         {
  22.             this.Name = name;
  23.             this.Price = price;
  24.             this.SerialNumber = serialNumber;
  25.             this.Quantity = quantity;
  26.             this.BoxPrice = boxPrice;
  27.         }
  28.  
  29.         public override string ToString()
  30.         {
  31.             return $@"{this.SerialNumber}
  32. -- {this.Name} - ${this.Price:f2}: {this.Quantity}
  33. -- ${this.BoxPrice:f2}";
  34.  
  35.  
  36.         }
  37.     }
  38.     class MainClass
  39.     {
  40.         public static void Main(string[] args)
  41.         {
  42.             List<Box> box = new List<Box>();
  43.  
  44.             string input;
  45.  
  46.             while ((input = Console.ReadLine()) != "end")
  47.             {
  48.                 string[] data = input.Split();
  49.  
  50.                 string serialNumber = data[0];
  51.                 string name = data[1];
  52.                 int quantity = int.Parse(data[2]);
  53.                 decimal price = decimal.Parse(data[3]);
  54.                 decimal boxPrice = price * quantity;
  55.  
  56.                 Box newBox = new Box(name, price, serialNumber, quantity, boxPrice);
  57.                 box.Add(newBox);
  58.             }
  59.  
  60.             box = box.OrderByDescending(x => x.BoxPrice).ToList();
  61.             Console.WriteLine(string.Join(Environment.NewLine, box));
  62.  
  63.  
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement