yanchevilian

06. Store Boxes ObjectsAndClasses-Lab

Feb 23rd, 2021 (edited)
57
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _06._Store_Boxes
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.             List<Box> allBoxes = new List<Box>();
  13.  
  14.             while (input != "end")
  15.             {
  16.                 string[] inputArr = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
  17.                 string serialNumber = inputArr[0];
  18.                 string itemName = inputArr[1];
  19.                 int itemQuantity = int.Parse(inputArr[2]);
  20.                 double itemPrice = double.Parse(inputArr[3]);
  21.  
  22.                 allBoxes.Add(new Box
  23.                 {
  24.                     SerialNumber = serialNumber,
  25.                     ItemQuantity = itemQuantity,
  26.                     PriceForABox = itemPrice,
  27.                     Item = new Item
  28.                     {
  29.                         Name = itemName,
  30.                         Price = itemPrice * itemQuantity
  31.                     }
  32.                 });
  33.                 input = Console.ReadLine();
  34.             }
  35.  
  36.             foreach (Box currentBox in allBoxes.OrderByDescending(x => x.Item.Price).ToList())
  37.             {
  38.                 Console.WriteLine($"{currentBox.SerialNumber}");
  39.                 Console.WriteLine($"-- {currentBox.Item.Name} – ${currentBox.PriceForABox:F2}: {currentBox.ItemQuantity}");
  40.                 Console.WriteLine($"-- ${currentBox.Item.Price:F2}");
  41.             }
  42.         }
  43.     }
  44.     class Box
  45.     {
  46.         //public Box()
  47.         //{
  48.         //    Item = new Item();
  49.         //}
  50.         public string SerialNumber { get; set; }
  51.         public Item Item { get; set; }
  52.         public int ItemQuantity { get; set; }
  53.         public double PriceForABox { get; set; }
  54.     }
  55.     class Item
  56.     {
  57.         public string Name { get; set; }
  58.         public double Price { get; set; }
  59.     }
  60. }
  61.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×