static void Main(string[] args) { // Creo un estante Estante estante = new Estante(3, 1); // Creo 4 productos Producto p1 = new Producto("Pepsi", "PESDS97413", (float)10.5); Producto p2 = new Producto("Coca-Cola", "COSDS55752", (float)10.5); Producto p3 = new Producto("Manaos", "MASDS51292", (float)10.5); Producto p4 = new Producto("Crush", "CRSDS54861", (float)10.5); // Agrego los productos al estante if (estante + p1) { Console.WriteLine("Agregó {0} {1} {2}", p1.GetMarca(), (string)p1, p1.GetPrecio()); } else { Console.WriteLine("¡NO agregó {0} {1} {2}!", p1.GetMarca(), (string)p1, p1.GetPrecio()); } if (estante + p1) { Console.WriteLine("Agregó {0} {1} {2}", p1.GetMarca(), (string)p1, p1.GetPrecio()); } else { Console.WriteLine("¡NO agregó {0} {1} {2}!", p1.GetMarca(), (string)p1, p1.GetPrecio()); } if (estante + p2) { Console.WriteLine("Agregó {0} {1} {2}", p2.GetMarca(), (string)p2, p2.GetPrecio()); } else { Console.WriteLine("¡NO agregó {0} {1} {2}!", p2.GetMarca(), (string)p2, p2.GetPrecio()); } if (estante + p3) { Console.WriteLine("Agregó {0} {1} {2}", p3.GetMarca(), (string)p3, p3.GetPrecio()); } else { Console.WriteLine("¡NO agregó {0} {1} {2}!", p3.GetMarca(), (string)p3, p3.GetPrecio()); } if (estante + p4) { Console.WriteLine("Agregó {0} {1} {2}", p4.GetMarca(), (string)p4, p4.GetPrecio()); } else { Console.WriteLine("¡NO agregó {0} {1} {2}!", p4.GetMarca(), (string)p4, p4.GetPrecio()); } // Muestro todo el estante Console.WriteLine(); Console.WriteLine("<------------------------------------------------->"); Console.WriteLine(Estante.MostrarEstante(estante)); Console.ReadKey(); }
public static string MostrarEstante(Estante e) { string estante = string.Format("Ubicacion: {0}\n", e.ubicacion); foreach (Producto p in e.GetProducto()) { if (!(p is null)) { estante += Producto.MostrarProducto(p); } } return(estante); }
public static string MostrarEstante(Estante e) { string retorno = "Ubicacion: " + e.ubicacionEstante + ". "; for (int i = 0; i < e.productos.Length; i++) { float precio = e.productos[i].GetPrecio(); if (precio > 0) { retorno = retorno + "Marca: " + e.productos[i].GetMarca() + ". " + "Codigo de barras: " + e.productos[i].GetCodigoDeBarra() + ". " + "Precio: " + precio + ". "; } } return(retorno); }
public static Estante operator -(Estante e, Producto p) { if (e == p) { Estante salida = new Estante(e.GetProducto().Rank, e.ubicacion); int i = 0; foreach (Producto producto in e.GetProducto()) { if (producto != p) { e.GetProducto()[i] = producto; i++; } } return(salida); } else { return(e); } }
public static string MostrarEstante(Estante e) { StringBuilder retorno = new StringBuilder(); string retornoTexto; retorno.Append(" Ubicacion estante: "); retorno.Append(e.ubicacionEstante); retorno.AppendLine(""); for (int i = 0; i < e.productos.Length; i++) { retorno.Append(" Producto "); retorno.Append(i + 1); retorno.AppendLine(": "); retorno.AppendLine(Producto.MostrarProducto(e.productos[i])); } retornoTexto = retorno.ToString(); return(retornoTexto); }