Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Problem_7._Store_Boxes_Лаб_Classes
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- List<Box> boxes = new List<Box>();
- while (input != "end")
- {
- string[] data = input.Split(" ").ToArray();
- int serialNumber = int.Parse(data[0]);
- string itemName = data[1];
- int itemQuantity = int.Parse(data[2]);
- double itemPrice = double.Parse(data[3]);
- Box box = new Box();
- box.SerialNumber = serialNumber;
- box.Item.Name = itemName;
- box.ItemQuantity = itemQuantity;
- box.Item.Price = itemPrice;
- box.SetThePrice();
- boxes.Add(box);
- input = Console.ReadLine();
- }
- List<Box> filtredBoxes = boxes.OrderByDescending(b => b.PriceForOneBox).ToList();
- foreach (Box item in filtredBoxes)
- {
- Console.WriteLine($"{item.SerialNumber}");
- Console.WriteLine($"-- {item.Item.Name} - ${item.Item.Price}: {item.ItemQuantity}");
- Console.WriteLine($"-- ${item.PriceForOneBox:f2}");
- }
- }
- }
- public class Item
- {
- public string Name { get; set; }
- public double Price { get; set; }
- }
- public class Box
- {
- public Box()
- {
- Item = new Item();
- }
- public int SerialNumber { get; set; }
- public Item Item { get; set; }
- public int ItemQuantity { get; set; }
- public double PriceForOneBox { get; set; }
- public void SetThePrice()
- {
- this.PriceForOneBox = ItemQuantity * Item.Price;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement