private void btnAgregar_Click(object sender, EventArgs e) { Botella botella; if (rbCerveza.Checked) { Botella.Tipo tipo; Enum.TryParse <Botella.Tipo>(this.cbTipoBotella.SelectedValue.ToString(), out tipo); botella = new Cerveza((int)this.nudCapacidad.Value, this.txtMarca.Text, tipo, (int)this.nupContenido.Value); this.barra.AgregarBotella(botella); MessageBox.Show(botella.ToString(), "CERVEZA"); } else { if (this.cbTipoBotella.Text == "Plastico") { botella = new Agua((int)this.nudCapacidad.Value, this.txtMarca.Text, (int)this.nupContenido.Value); this.barra.AgregarBotella(botella); MessageBox.Show(botella.ToString(), "AGUA"); } else { MessageBox.Show(" No tenemos agua en envase de vidrio"); } } }
private void btn_Agregar_Click(object sender, EventArgs e) { if (rdn_Cerveza.Checked) { Botella botellaCerveza = new Cerveza((int)num_Capacidad.Value, (int)num_Contenido.Value, txt_Marca.Text); this.barra.AgregarBotella(botellaCerveza); MessageBox.Show($"{botellaCerveza.ToString()} \nSe agregó la cerveza", "Alcohol", MessageBoxButtons.OK); } else { Botella botellaAgua = new Agua((int)num_Capacidad.Value, (int)num_Contenido.Value, txt_Marca.Text); barra.AgregarBotella(botellaAgua); MessageBox.Show($"{botellaAgua.ToString()} \nSe agregó el agua", "Awita", MessageBoxButtons.OK); } }
static void Main(string[] args) { Cantina cantina; Cerveza c1 = new Cerveza(1000, "Honey", 500); Cerveza c2 = new Cerveza(2000, "IPA", Botella.Tipo.Plastico, 2050); Agua a = new Agua(500, "Los Andes", 350); Agua a2 = new Agua(500, "Los Andes", 350); cantina = Cantina.GetCantina(3); if (cantina + c1) { c1.ServirMedida(); Console.WriteLine(c1.ToString()); } Console.WriteLine(); if (cantina + c2) { c2.ServirMedida(); Console.WriteLine(c2.ToString()); } Console.WriteLine(); if (cantina + a) { a.ServirMedida(67); Console.WriteLine(a.ToString()); } Console.WriteLine(); if (cantina + a2) { a2.ServirMedida(); Console.WriteLine(a2.ToString()); } Console.ReadKey(); }