public static void Main()
Customer[] objCustomer = new Customer[2];
new PrintOrders().PrintOrder(objCustomer);
public static void FillData(Customer[] objCustomer)
objCustomer[0] = new Customer("Salma", "habib");
objCustomer[0].CustomerOrder[0] = new Order(new Motocycle(2, "ATK 450 Enduro 2008", 48, 25, 40), 4200, 1);
objCustomer[1] = new Customer("Jo", "Je");
objCustomer[1].CustomerOrder[0] = new Order(new Automobiles(2, "BMW R1 1500 2015", 50, 20, 40, 70), 5200, 1);
public Customer(string fName, string lName)
CustommerFirstName1 = fName;
CustomerLastName1 = lName;
public string CustommerFirstName1 { get; set; }
public string CustomerLastName1 { get; set; }
public Order[] CustomerOrder = new Order[3];
public Order(IVehicle iv, decimal price, int qty)
public IVehicle OrderDesc { get; set; }
public decimal OrderPrice { get; set; }
public int OrderQty { get; set; }
public interface IVehicle
int NumOfWheels { get; set; }
string Description { get; set; }
double HoursePower { get; set; }
double CargoCapacity { get; set; }
class Motocycle : IVehicle
public Motocycle(int numOfWheel, string des, double hpower, double radius, double height)
_numOfWheels = numOfWheel;
const double Pi = 3.141592653589793238462643;
get { return _numOfWheels; }
set { _numOfWheels = value; }
string IVehicle.Description
get { return _description; }
set { _description = value; }
double IVehicle.HoursePower
get { return _hoursePower; }
set { _hoursePower = value; }
public double Radius { get; set; }
public double Height { get; set; }
private double _cargoCapacity;
public double CargoCapacity
get { return (Pi * (Radius * Radius) * Height) * 2; }
set { _cargoCapacity = value; }
class Automobiles : IVehicle
public Automobiles(int numOfWheel, string des, double hpower, double width, double height, double length)
_numOfWheels = numOfWheel;
get { return _numOfWheels; }
set { _numOfWheels = value; }
string IVehicle.Description
get { return _description; }
set { _description = value; }
double IVehicle.HoursePower
get { return _hoursePower; }
set { _hoursePower = value; }
public double Width { get; set; }
public double Length { get; set; }
public double Height { get; set; }
private double _cargoCapacity;
public double CargoCapacity
get { return (Length * Width * Height); }
set { _cargoCapacity = value; }
void PrintOrder(Customer[] cust);
public class PrintOrders : IPrintOrders
public void PrintOrder(Customer[] cust)
StringBuilder sb = new StringBuilder();
foreach (var custItem in cust)
sb.AppendLine($"Customer Name :{custItem.CustommerFirstName1} {custItem.CustomerLastName1}");
sb.AppendLine(" Orders : ");
foreach (var item in custItem.CustomerOrder)
sb.AppendLine($"Description : {item.OrderDesc.Description}");
sb.AppendLine($"Cargo Capacity : {item.OrderDesc.CargoCapacity:F1}");
sb.AppendLine($"\t\t\t{item.OrderPrice:C} - {item.OrderQty} ");
public void writeOnConsole(StringBuilder sb)
public void WriteONFile(StringBuilder sb)
string wantedPath = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())) +
$"\\Output{DateTime.Now.ToString(("yyyyMMddhhmmss"))}.txt";
FileStream fs1 = new FileStream(wantedPath, FileMode.OpenOrCreate, FileAccess.Write);
using (StreamWriter sw = new StreamWriter(fs1))