Advertisement
wis3_guy

Account Executive Program update 1.1

Feb 13th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace applicationName
  8. {
  9. public class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. //Declare new lists based on the discounts each customer will receive
  14. CustomerGroup noDiscountCg = new CustomerGroup();
  15. CustomerGroup lowDiscountCg = new CustomerGroup();
  16. CustomerGroup highDiscountCg = new CustomerGroup();
  17.  
  18. List<Customer> unsortedCustomer = new List<Customer>
  19. {
  20. //Adding customers to the unsorted list
  21. new Customer(123456, "Thom Yorke", "215 Chestnut Lane", "thomyorke@radiohead.com", 2569876548, new DateTime(2013, 1, 9), 500),
  22. new Customer(852963, "Annie Clark", "879 Hickory Road", "annieclark@gmail.com", 3135453404, new DateTime(2002, 11, 12), 200),
  23. new Customer(147987, "Claire Boucher", "200 Dogwood Drive", "claireboucher@gmail.com", 9635874102, new DateTime(2000, 10, 11), 10),
  24. new Customer(357951, "Sophie Hutchings", "963 Highview Court", "sophiehutchings@gmail.com", 2510147756, new DateTime(2007, 8, 8), 400),
  25. new Customer(789987, "Danny Teague", "8410 Greensboro Road ", "teague@gmail.com", 2315648974, new DateTime(2011, 4, 4), 60),
  26. new Customer(753963, "Brian McBride", "444 Buena Vista Court", "brianmcbride1@gmail.com", 7899877410, new DateTime(2003, 10, 10), 560),
  27. new Customer(200132, "David Bowie", "921 Washington Ave", "davidbowie@gmail.com", 4566541230, new DateTime(2000, 1, 1), 910),
  28. new Customer(452631, "Aidan Baker", "741 Palm Springs Road", "abaker@gmail.com", 1233210123, new DateTime(2005, 5, 5), 700),
  29. new Customer(687952, "Ben Frost", "563 Cedar Lane", "benfrost@gmail.com", 8256987654, new DateTime(2013, 2, 9), 890),
  30. new Customer(985204, "Bill Laswell", "10 Pennsylvania Ave", "blaswell@gmail.com", 3413545340, new DateTime(2004, 12, 12), 201),
  31. new Customer(112154, "Claude Debussy", "852 Stone Brook Road", "cdebussy@gmail.com", 5874963102, new DateTime(2001, 2, 5), 101),
  32. new Customer(311159, "James Blake", "700 Mountain View Drive", "jamesblake@gmail.com", 2477510156, new DateTime(2007, 7, 3), 630)
  33. };
  34.  
  35.  
  36. //Loop that sorts based on discounts given number of average transactions
  37. //Assigns each unsorted customer into a new group based on the discount they'll receive
  38. foreach (Customer temporary in unsortedCustomer)
  39. {
  40. if (temporary.CalcTransaction() <= 3)
  41. {
  42. noDiscountCg.CustomerList.Add(temporary);
  43. }
  44.  
  45. else if (temporary.CalcTransaction() > 6)
  46.  
  47. {
  48. lowDiscountCg.CustomerList.Add(temporary);
  49. }
  50.  
  51. else if (temporary.CalcTransaction() > 15)
  52. {
  53. highDiscountCg.CustomerList.Add(temporary);
  54. }
  55. }
  56.  
  57. //Assign unique ID's to each customer group
  58.  
  59. noDiscountCg.GroupID = 200;
  60. lowDiscountCg.GroupID = 500;
  61. highDiscountCg.GroupID = 700;
  62.  
  63. FileStream ostrm;
  64. StreamWriter writer;
  65. TextWriter oldOut = Console.Out;
  66. try
  67. {
  68. ostrm = new FileStream("./sorted_customer_list.txt", FileMode.OpenOrCreate, FileAccess.Write);
  69. writer = new StreamWriter(ostrm);
  70. }
  71. catch (Exception e)
  72. {
  73. Console.WriteLine("Cannot open sorted_customer_list.txt for writing");
  74. Console.WriteLine(e.Message);
  75. return;
  76. }
  77. Console.SetOut(writer);
  78.  
  79.  
  80. //Assign account executive to each group
  81. NoDiscountCustomerGroup(noDiscountCg);
  82. LowDiscountCustomerGroup(lowDiscountCg);
  83. HighDiscountCustomerGroup(highDiscountCg);
  84.  
  85. Console.SetOut(oldOut);
  86. writer.Close();
  87. ostrm.Close();
  88. Console.WriteLine("Done.");
  89. Console.WriteLine("This text file is located in the Debug subfolder within the Bin folder.");
  90.  
  91. }
  92.  
  93. private static void HighDiscountCustomerGroup(CustomerGroup highDiscountCg)
  94. {
  95. highDiscountCg.AccountExecutive.Name = "Tim Hecker";
  96. Console.WriteLine("The following customers will be assigned to the account executive named " + highDiscountCg.AccountExecutive.Name);
  97. Console.WriteLine("This customer will be placed in group number " + highDiscountCg.GroupID);
  98. foreach (Customer Customer in highDiscountCg.CustomerList)
  99. {
  100. Console.WriteLine(Customer.Name);
  101. Console.WriteLine(Customer.TotalTransactions);
  102. }
  103. }
  104.  
  105. private static void LowDiscountCustomerGroup(CustomerGroup lowDiscountCg)
  106. {
  107. lowDiscountCg.AccountExecutive.Name = "Brian Williams";
  108. Console.WriteLine("The following customers will be assigned to the account executive named " + lowDiscountCg.AccountExecutive.Name);
  109. Console.WriteLine("This customer will be placed in group number " + lowDiscountCg.GroupID);
  110. foreach (Customer Customer in lowDiscountCg.CustomerList)
  111. {
  112. Console.WriteLine(Customer.Name);
  113. Console.WriteLine(Customer.TotalTransactions);
  114. }
  115. }
  116.  
  117. private static void NoDiscountCustomerGroup(CustomerGroup noDiscountCg)
  118. {
  119. noDiscountCg.AccountExecutive.Name = "Robert Rich";
  120. Console.WriteLine("The following customers will be assigned to the account executive named " + noDiscountCg.AccountExecutive.Name);
  121. Console.WriteLine("This customer will be placed in group number " + noDiscountCg.GroupID);
  122. foreach (Customer Customer in noDiscountCg.CustomerList)
  123. {
  124. Console.WriteLine(Customer.Name);
  125. Console.WriteLine(Customer.TotalTransactions);
  126. }
  127. }
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement