using System.Collections.Generic;
static void Main(string[] args)
Cliente cliente1 = new Cliente();
cliente1.Apellido = "Linares";
Sucursal sucursal1 = new Sucursal("Av. Camacho");
Factura factura1 = new Factura(100, DateTime.Now, cliente1);
factura1.Sucursal = sucursal1;
Producto pro1 = new Producto("Agua vital", 5);
Producto pro2 = new Producto("Pan", 5);
Producto pro3 = new Producto("Papaya", 10);
factura1.AgregarItem(pro1, 2);
factura1.AgregarItem(pro2, 1);
factura1.AgregarItem(pro3, 1);
Factura factura2 = new Factura(200, DateTime.Now, cliente1);
factura2.Sucursal = sucursal1;
Producto pro4 = new Producto("Chocolate", 15);
Producto pro5 = new Producto("Carne", 45);
factura2.AgregarItem(pro5, 2);
private List<Item> items;
public int Numero { get; set; }
public DateTime Fecha { get; set; }
public Cliente Cliente { get; set; }
public Sucursal Sucursal { get; set; }
public IReadOnlyCollection<Item> Items
get { return items.AsReadOnly(); }
public Factura(int numero, DateTime fe, Cliente cli)
throw new Exception("Imposible crear sin un cliente asociado");
items = new List<Item>();
public void AgregarItem(Producto pro, int can)
Item item = new Item(pro, can);
public double CalcularTotal()
foreach (Item ele in items)
total = total + (ele.Producto.Precio * ele.Cantidad);
Console.WriteLine("La sucursal es =" + Sucursal.Direccion);
Console.WriteLine("Numero de la factura =" + Numero);
Console.WriteLine("Fecha de la factura =" + Fecha);
Console.WriteLine("Nombre del cliente =" + Cliente.Nombre);
Console.WriteLine("Apellido del cliente=" + Cliente.Apellido);
foreach (Item ele in items)
Console.WriteLine("Descripcion:" + ele.Producto.Descripcion + "Precio:" + ele.Producto.Precio + "Cantidad:" + ele.Cantidad +
"Subtotal:" + (ele.Producto.Precio * ele.Cantidad));
Console.WriteLine("El total de la factura es:" + CalcularTotal());
public string Nombre { get; set; }
public string Apellido { get; set; }
public string Direccion { get; set; }
public Sucursal(string dir)
public Producto Producto { get; set; }
public int Cantidad { get; set; }
public Item(Producto pro, int can)
public string Descripcion { get; set; }
public double Precio { get; set; }
public Producto(string des, double pre)