Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp53
  8. {
  9. class Program
  10. {
  11. class Item
  12. {
  13. public double price;
  14. public double quantity;
  15.  
  16. public Item(double p, double q)
  17. {
  18. price = p;
  19. quantity = q;
  20. }
  21.  
  22. public double GetTotalPrice()
  23. {
  24. return price * quantity;
  25. }
  26. public void UpdateQuantityAndPrice(double price, double newQuantity)
  27. {
  28. quantity += newQuantity;
  29. this.price = price;
  30.  
  31. }
  32.  
  33.  
  34. }
  35. static void Main(string[] args)
  36. {
  37. var orders = new Dictionary<String, Item>();
  38. string input = string.Empty;
  39.  
  40. while ((input = Console.ReadLine()) != "buy")
  41. {
  42.  
  43. string[] inputStrings = input.Split();
  44.  
  45. if (!orders.ContainsKey(inputStrings[0]))
  46. {
  47. Item item = new Item(double.Parse(inputStrings[1]), double.Parse(inputStrings[2]));
  48. orders.Add(inputStrings[0], item);
  49. }
  50. else
  51. {
  52. Item curItem = orders[inputStrings[0]];
  53. curItem.UpdateQuantityAndPrice(double.Parse(inputStrings[1]), double.Parse(inputStrings[2]));
  54. }
  55.  
  56. }
  57.  
  58. foreach (var kvp in orders)
  59. {
  60. Console.WriteLine($"{kvp.Key} -> {kvp.Value.GetTotalPrice():F2}");
  61. }
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement