Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _07._Store_Boxes
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Box> boxes = new List<Box>();
- while (true)
- {
- string[] informationForBoxes = Console.ReadLine().Split().ToArray();
- if (informationForBoxes[0] == "end")
- {
- List<Box> result = boxes.OrderByDescending(x => x.ItemPrice).ToList();
- foreach (var box in result)
- {
- Console.WriteLine(box.SerialNumber);
- Console.WriteLine($"-- {box.ItemName.Name} - ${box.ItemName.Price:f2}: {box.ItemQuantity}");
- Console.WriteLine($"-- ${box.PriceOfBox:f2}");
- }
- }
- else
- {
- boxes.Add(new Box(informationForBoxes));
- }
- }
- }
- }
- class Item
- {
- public string Name { get; set; }
- public double Price { get; set; }
- public Item (string itemName, double ItemPrice)
- {
- this.Name = itemName;
- this.Price = ItemPrice;
- }
- }
- class Box
- {
- public int SerialNumber { get; set; }
- public Item ItemName { get; set; }
- public int ItemQuantity { get; set; }
- public double ItemPrice { get; set; }
- public double PriceOfBox { get; set; }
- public Box(string []informationForBoxes)
- {
- SerialNumber = int.Parse(informationForBoxes[0]);
- ItemQuantity = int.Parse(informationForBoxes[2]);
- ItemPrice = double.Parse(informationForBoxes[3]);
- PriceOfBox = ItemQuantity * ItemPrice;
- string itemName = informationForBoxes[1];
- ItemName = new Item(itemName, ItemPrice);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment