Created with <3 with dartpad.dev.
Created
October 31, 2023 02:59
-
-
Save leonus96/7d4c761fd8a53781a12400b2a1556bfc to your computer and use it in GitHub Desktop.
7. inventario
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////Ejercicio 6: Gestión de Inventario | |
/// Crea una clase llamada Producto con | |
/// propiedades como nombre, precio y cantidad | |
/// en stock. Luego, crea funciones para agregar, | |
/// eliminar y actualizar productos en un inventario. | |
class Producto { | |
int codigo; | |
String nombre; | |
double precio; | |
int cantidad; | |
Producto({ | |
required this.codigo, | |
required this.nombre, | |
required this.precio, | |
required this.cantidad, | |
}); | |
} | |
void main() { | |
final List<Producto> inventario = [ | |
Producto(codigo: 23, nombre: 'G.Soda', precio: 0.5, cantidad: 0), | |
Producto(codigo: 34, nombre: 'G.Coronita', precio: 0.5, cantidad: 0), | |
Producto(codigo: 21, nombre: 'G.Frac', precio: 0.8, cantidad: 0), | |
Producto(codigo: 65, nombre: 'G.Tentación', precio: 0.8, cantidad: 0), | |
Producto(codigo: 38, nombre: 'G.Gretell', precio: 0.8, cantidad: 0), | |
]; | |
print(inventario.length); | |
eliminarProducto(inventario, 23); | |
print(inventario.length); | |
} | |
void actualizarCantidad(List<Producto> inventario, int codigo, int cantidad) { | |
for (Producto producto in inventario) { | |
if (producto.codigo == codigo) { | |
producto.cantidad = cantidad; | |
} | |
} | |
} | |
void eliminarProducto(List<Producto> inventario, int codigo) { | |
for (int i = 0; i < inventario.length; i++) { | |
if (inventario[i].codigo == codigo) { | |
inventario.removeAt(i); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment