h dave

h dave

  • NA
  • 50
  • 3.9k

I am creating billing app not sure where I am going wrong

Jul 16 2020 1:20 AM
Bill.cs
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4. namespace ConsoleApp2  
  5. {  
  6. public class Bill  
  7. {  
  8. public int BillNumber { getset; }  
  9. public DateTime BillDate { getset; }  
  10. public List LineItems { getset; } = new List();  
  11. public void AddBillLine(BillLine billLine)  
  12. {  
  13. LineItems.Add(billLine);  
  14. }  
  15. public void RemoveBillLine(int SOMEID)  
  16. {  
  17. throw new NotImplementedException();  
  18. }  
  19. ///  
  20. /// GetTotal should return the sum of (Cost * Quantity) for each line item  
  21. ///  
  22. public decimal GetTotal()  
  23. {  
  24. throw new NotImplementedException();  
  25. }  
  26. ///  
  27. /// MergeBill appends the items from the sourceBill to the current bill  
  28. ///  
  29. /// Bill to merge from  
  30. public void MergeBill(Bill sourceBill)  
  31. {  
  32. throw new NotImplementedException();  
  33. }  
  34. ///  
  35. /// Creates a deep clone of the current bill (all fields and properties)  
  36. ///  
  37. public Bill Clone()  
  38. {  
  39. throw new NotImplementedException();  
  40. }  
  41. ///  
  42. /// Outputs string containing the following (replace [] with actual values):  
  43. /// Bill Number: [BillNumber], BillDate: [dd/MM/yyyy], LineItemCount: [Number of items in LineItems]  
  44. ///  
  45. public override string ToString()  
  46. {  
  47. throw new NotImplementedException();  
  48. }  
  49. }  
  50. }  
  51. BillLine.cs  
  52. namespace ConsoleApp2  
  53. {  
  54. public class BillLine  
  55. {  
  56. public int BillLineId { getset; }  
  57. public string Description { getset; }  
  58. public int Quantity { getset; }  
  59. public double Cost { getset; }  
  60. }  
  61. }  
  62.  Program.cs  
  63.    
  64. using System;  
  65. using System.Collections.Generic;  
  66. namespace ConsoleApp2  
  67. {  
  68. public class Program  
  69. {  
  70. static void Main(string[] args)  
  71. {  
  72. Console.WriteLine("Billing app started....");  
  73. CreateBillWithOneItem();  
  74. CreateBillWithMultipleItemsAndQuantities();  
  75. RemoveItem();  
  76. MergeBill();  
  77. CloneBill();  
  78. BillToString();  
  79. }  
  80. private static void CreateBillWithOneItem()  
  81. {  
  82. var bill = new Bill();  
  83. bill.AddBillLine(new BillLine()  
  84. {  
  85. BillLineId = 1,  
  86. Cost = 6.99,  
  87. Quantity = 1,  
  88. Description = "Apple"  
  89. });  
  90. Console.WriteLine(bill.GetTotal());  
  91. }  
  92. private static void CreateBillWithMultipleItemsAndQuantities()  
  93. {  
  94. var bill = new Bill();  
  95. bill.AddBillLine(new BillLine()  
  96. {  
  97. BillLineId = 1,  
  98. Cost = 10.21,  
  99. Quantity = 4,  
  100. Description = "Banana"  
  101. });  
  102. bill.AddBillLine(new BillLine()  
  103. {  
  104. BillLineId = 2,  
  105. Cost = 5.21,  
  106. Quantity = 1,  
  107. Description = "Orange"  
  108. });  
  109. bill.AddBillLine(new BillLine()  
  110. {  
  111. BillLineId = 3,  
  112. Cost = 5.21,  
  113. Quantity = 5,  
  114. Description = "Pineapple"  
  115. });  
  116. Console.WriteLine(bill.GetTotal());  
  117. }  
  118. private static void RemoveItem()  
  119. {  
  120. var bill = new Bill();  
  121. bill.AddBillLine(new BillLine()  
  122. {  
  123. BillLineId = 1,  
  124. Cost = 5.21,  
  125. Quantity = 1,  
  126. Description = "Orange"  
  127. });  
  128. bill.AddBillLine(new BillLine()  
  129. {  
  130. BillLineId = 2,  
  131. Cost = 10.99,  
  132. Quantity = 4,  
  133. Description = "Banana"  
  134. });  
  135. bill.RemoveBillLine(1);  
  136. Console.WriteLine(bill.GetTotal());  
  137. }  
  138. private static void MergeBill()  
  139. {  
  140. var bill1 = new Bill();  
  141. bill1.AddBillLine(new BillLine()  
  142. {  
  143. BillLineId = 1,  
  144. Cost = 10.33,  
  145. Quantity = 4,  
  146. Description = "Banana"  
  147. });  
  148. var bill2 = new Bill();  
  149. bill2.AddBillLine(new BillLine()  
  150. {  
  151. BillLineId = 2,  
  152. Cost = 5.22,  
  153. Quantity = 1,  
  154. Description = "Orange"  
  155. });  
  156. bill2.AddBillLine(new BillLine()  
  157. {  
  158. BillLineId = 3,  
  159. Cost = 6.27,  
  160. Quantity = 3,  
  161. Description = "Blueberries"  
  162. });  
  163. bill1.MergeBill(bill2);  
  164. Console.WriteLine(bill1.GetTotal());  
  165. }  
  166. private static void CloneBill()  
  167. {  
  168. var bill = new Bill();  
  169. bill.AddBillLine(new BillLine()  
  170. {  
  171. BillLineId = 1,  
  172. Cost = 6.99,  
  173. Quantity = 1,  
  174. Description = "Apple"  
  175. });  
  176. bill.AddBillLine(new BillLine()  
  177. {  
  178. BillLineId = 2,  
  179. Cost = 6.27,  
  180. Quantity = 3,  
  181. Description = "Blueberries"  
  182. });  
  183. var clonedBill = bill.Clone();  
  184. Console.WriteLine(clonedBill.GetTotal());  
  185. }  
  186. private static void BillToString()  
  187. {  
  188. var bill = new Bill()  
  189. {  
  190. BillDate = DateTime.Now,  
  191. BillNumber = 1000,  
  192. LineItems = new List()  
  193. {  
  194. new BillLine()  
  195. {  
  196. BillLineId = 1,  
  197. Cost = 6.99,  
  198. Quantity = 1,  
  199. Description = "Apple"  
  200. }  
  201. }  
  202. };  
  203. Console.WriteLine(bill.ToString());  
  204. }  
  205. }  
  206. }  
Can anyone please help on this I want to know how I can create bill for one item,  create bill with multiple items and quantities, remove item, merge bill, clone bill.

Answers (3)