Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- static void Main(string[] args)
- {
- List<Box> boxes = new List<Box>();
- string input = string.Empty;
- while ((input=Console.ReadLine())!="end")
- {
- string[] tokens = input.Split(' ');
- string serialNumber = tokens[0];
- string itemName = tokens[1];
- int itemQuantity = int.Parse(tokens[2]);
- decimal itemPrice = decimal.Parse(tokens[3]);
- boxes.Add(new Box(serialNumber, itemName, itemQuantity, itemPrice));
- }
- boxes.OrderByDescending(b=>b.GetBoxPrice()).ToList().ForEach(b => Console.WriteLine(b));
- }
- }
- class Box
- {
- public Box(string serialNumber, string itemName,int itemQuantity,decimal itemPrice)
- {
- this.SerialNumber = serialNumber;
- this.ItemName = itemName;
- this.ItemQuantity = itemQuantity;
- this.ItemPrice = itemPrice;
- }
- public string SerialNumber { get; set; }
- public string ItemName { get; set; }
- public int ItemQuantity { get; set; }
- public decimal ItemPrice { get; set; }
- public decimal GetBoxPrice()
- {
- return this.ItemPrice * this.ItemQuantity;
- }
- public override string ToString()
- {
- return this.SerialNumber +
- Environment.NewLine +
- $"-- {this.ItemName} - ${this.ItemPrice:F2}: {this.ItemQuantity}"+
- Environment.NewLine +
- $"-- ${this.GetBoxPrice():F2}";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement