public static void Main()
var path = @"C:\Hamed_Assignment3";
var filename = @"C:\Hamed_Assignment3\Assignment3.txt";
var cust = Customerses(out sumc1, out sumc2);
decimal masterCardTotal = 0;
foreach (var customer in cust)
if (customer == null) continue;
Console.WriteLine("Customer:\n");
Console.WriteLine("{0, 15} {1, 17}", "First Name", "Last Name");
Console.WriteLine("{0, 10} {1, 20}", customer.FirstName, customer.LastName);
Console.WriteLine("-----------------------------------------------");
Console.WriteLine("Orders:\n");
foreach (var order in customer.Order)
visaTotal = Total(order, visaTotal, ref masterCardTotal, ref payPalTotal);
Console.WriteLine("==========================================");
Console.WriteLine("Total sales: {0:C}\n", masterCardTotal + visaTotal + payPalTotal);
Console.WriteLine("MasterCard Total: {0:C}", masterCardTotal);
Console.WriteLine("Visa Total: {0:C}", visaTotal);
Console.WriteLine("PayPal Total: {0:C}", payPalTotal);
IPayment payPal = new PayPal();
IPayment visa = new Visa();
IPayment masterCard = new MasterCard();
Console.WriteLine("-----------------------------------------");
var di = new DirectoryInfo(path);
Console.WriteLine("The directory *{0}* already exists.", path);
Console.WriteLine("The directory was created in *{0}* successfully.", path);
using (var file = new StreamWriter(filename, true))
var myfile1 = "Name:" + cust[0].FirstName + cust[0].LastName + " " + "Total: $" + sumc1;
var myfile2 = "Name:" + cust[1].FirstName + cust[1].LastName + " " + "Total: $" + sumc2;
private static decimal Total(Orders order, decimal visaTotal, ref decimal masterCardTotal,
if (order == null) return visaTotal;
Console.WriteLine("{0, 10} {1, 10} {2, 10}", order.Description, order.Price, order.Quantity);
if (order.Payment is Visa)
visaTotal += order.Price;
else if (order.Payment is MasterCard)
masterCardTotal += order.Price;
else if (order.Payment is PayPal)
payPalTotal += order.Price;
private static Customers[] Customerses(out decimal sumc1, out decimal sumc2)
var cust = new Customers[3];
cust[0] = new Customers {FirstName = "Joe", LastName = "Smith", Order = new Orders[3]};
cust[0].Order[0] = new Orders
Payment = new MasterCard()
cust[0].Order[1] = new Orders {Description = "Pants", Price = 29.99M, Quantity = 2, Payment = new Visa()};
sumc1 = (cust[0].Order[0].Quantity*cust[0].Order[0].Price) +
(cust[0].Order[1].Quantity*cust[0].Order[1].Price);
cust[1] = new Customers {FirstName = "Sally", LastName = "Jones", Order = new Orders[3]};
cust[1].Order[0] = new Orders {Description = "Shoes", Price = 39.99M, Quantity = 1, Payment = new Visa()};
cust[1].Order[1] = new Orders {Description = "Pants", Price = 49.99M, Quantity = 1, Payment = new PayPal()};
sumc2 = (cust[1].Order[0].Quantity*cust[1].Order[0].Price) +
(cust[1].Order[1].Quantity*cust[1].Order[1].Price);
public string Description;
public IPayment Payment { get; set; }
internal interface IPayment
internal class PayPal : IPayment
internal class Visa : IPayment
internal class MasterCard : IPayment