Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace applicationName
- {
- public class Program
- {
- static void Main(string[] args)
- {
- //Declare new lists based on the discounts each customer will receive
- CustomerGroup noDiscountCg = new CustomerGroup();
- CustomerGroup lowDiscountCg = new CustomerGroup();
- CustomerGroup highDiscountCg = new CustomerGroup();
- List<Customer> unsortedCustomer = new List<Customer>
- {
- //Adding customers to the unsorted list
- new Customer(123456, "Thom Yorke", "215 Chestnut Lane", "thomyorke@radiohead.com", 2569876548, new DateTime(2013, 1, 9), 500),
- new Customer(852963, "Annie Clark", "879 Hickory Road", "annieclark@gmail.com", 3135453404, new DateTime(2002, 11, 12), 200),
- new Customer(147987, "Claire Boucher", "200 Dogwood Drive", "claireboucher@gmail.com", 9635874102, new DateTime(2000, 10, 11), 10),
- new Customer(357951, "Sophie Hutchings", "963 Highview Court", "sophiehutchings@gmail.com", 2510147756, new DateTime(2007, 8, 8), 400),
- new Customer(789987, "Danny Teague", "8410 Greensboro Road ", "teague@gmail.com", 2315648974, new DateTime(2011, 4, 4), 60),
- new Customer(753963, "Brian McBride", "444 Buena Vista Court", "brianmcbride1@gmail.com", 7899877410, new DateTime(2003, 10, 10), 560),
- new Customer(200132, "David Bowie", "921 Washington Ave", "davidbowie@gmail.com", 4566541230, new DateTime(2000, 1, 1), 910),
- new Customer(452631, "Aidan Baker", "741 Palm Springs Road", "abaker@gmail.com", 1233210123, new DateTime(2005, 5, 5), 700),
- new Customer(687952, "Ben Frost", "563 Cedar Lane", "benfrost@gmail.com", 8256987654, new DateTime(2013, 2, 9), 890),
- new Customer(985204, "Bill Laswell", "10 Pennsylvania Ave", "blaswell@gmail.com", 3413545340, new DateTime(2004, 12, 12), 201),
- new Customer(112154, "Claude Debussy", "852 Stone Brook Road", "cdebussy@gmail.com", 5874963102, new DateTime(2001, 2, 5), 101),
- new Customer(311159, "James Blake", "700 Mountain View Drive", "jamesblake@gmail.com", 2477510156, new DateTime(2007, 7, 3), 630)
- };
- //Loop that sorts based on discounts given number of average transactions
- //Assigns each unsorted customer into a new group based on the discount they'll receive
- foreach (Customer temporary in unsortedCustomer)
- {
- if (temporary.CalcTransaction() <= 3)
- {
- noDiscountCg.CustomerList.Add(temporary);
- }
- if (temporary.CalcTransaction() > 6)
- {
- lowDiscountCg.CustomerList.Add(temporary);
- }
- if (temporary.CalcTransaction() > 15)
- {
- highDiscountCg.CustomerList.Add(temporary);
- }
- }
- //Assign unique ID's to each customer group
- noDiscountCg.GroupID = 200;
- lowDiscountCg.GroupID = 500;
- highDiscountCg.GroupID = 700;
- FileStream ostrm;
- StreamWriter writer;
- TextWriter oldOut = Console.Out;
- try
- {
- ostrm = new FileStream("./sorted_customer_list.txt", FileMode.OpenOrCreate, FileAccess.Write);
- writer = new StreamWriter(ostrm);
- }
- catch (Exception e)
- {
- Console.WriteLine("Cannot open sorted_customer_list.txt for writing");
- Console.WriteLine(e.Message);
- return;
- }
- Console.SetOut(writer);
- //Assign account executive to each group
- NoDiscountCustomerGroup(noDiscountCg);
- LowDiscountCustomerGroup(lowDiscountCg);
- HighDiscountCustomerGroup(highDiscountCg);
- Console.SetOut(oldOut);
- writer.Close();
- ostrm.Close();
- Console.WriteLine("Done.");
- Console.WriteLine("This text file is located in the Debug subfolder within the Bin folder.");
- }
- private static void HighDiscountCustomerGroup(CustomerGroup highDiscountCg)
- {
- highDiscountCg.AccountExecutive.Name = "Tim Hecker";
- Console.WriteLine("The following customers will be assigned to the account executive named " + highDiscountCg.AccountExecutive.Name);
- Console.WriteLine("This customer will be placed in group number " + highDiscountCg.GroupID);
- foreach (Customer Customer in highDiscountCg.CustomerList)
- {
- Console.WriteLine(Customer.Name);
- Console.WriteLine(Customer.TotalTransactions);
- }
- }
- private static void LowDiscountCustomerGroup(CustomerGroup lowDiscountCg)
- {
- lowDiscountCg.AccountExecutive.Name = "Brian Williams";
- Console.WriteLine("The following customers will be assigned to the account executive named " + lowDiscountCg.AccountExecutive.Name);
- Console.WriteLine("This customer will be placed in group number " + lowDiscountCg.GroupID);
- foreach (Customer Customer in lowDiscountCg.CustomerList)
- {
- Console.WriteLine(Customer.Name);
- Console.WriteLine(Customer.TotalTransactions);
- }
- }
- private static void NoDiscountCustomerGroup(CustomerGroup noDiscountCg)
- {
- noDiscountCg.AccountExecutive.Name = "Robert Rich";
- Console.WriteLine("The following customers will be assigned to the account executive named " + noDiscountCg.AccountExecutive.Name);
- Console.WriteLine("This customer will be placed in group number " + noDiscountCg.GroupID);
- foreach (Customer Customer in noDiscountCg.CustomerList)
- {
- Console.WriteLine(Customer.Name);
- Console.WriteLine(Customer.TotalTransactions);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement