Examen 2025/02/21
This commit is contained in:
63
src/main/java/examenes/examen20250221/ejercicio01/Main.java
Normal file
63
src/main/java/examenes/examen20250221/ejercicio01/Main.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package examenes.examen20250221.ejercicio01;
|
||||
|
||||
import examenes.examen20250221.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
HashMap<String, Producto> productos = new HashMap<>();
|
||||
int opcion;
|
||||
|
||||
productos.put("Cocacola", new Producto(1,"Cocacola", 1));
|
||||
productos.put("Pepsi", new Producto(1,"Pepsi", 1.2));
|
||||
productos.put("Galletas", new Producto(1,"Galletas", 0.8));
|
||||
productos.put("Chicles", new Producto(1,"Chicles", 0.25));
|
||||
|
||||
do {
|
||||
System.out.println("Seleccione lo que desea hacer:\n" +
|
||||
"0. Salir\n" +
|
||||
"1. Introducir productos\n" +
|
||||
"2. Mostrar producto más barato\n" +
|
||||
"3. Mostrar productos ordenados de más caro a más barato");
|
||||
|
||||
opcion = Utils.solicitarIntScannerInline("> ");
|
||||
switch (opcion) {
|
||||
case 1:
|
||||
Producto productoNuevo = new Producto(
|
||||
Utils.solicitarIntScannerInline("Introduzca el código del producto: "),
|
||||
Utils.solicitarStringScannerInline("Introduzca el nombre del producto: "),
|
||||
Utils.solicitarDoubleScannerInline("Introduzca el precio del producto: ")
|
||||
);
|
||||
productos.put(productoNuevo.getNombre(), productoNuevo);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
List<Producto> listaProductosPrimerItem = new ArrayList<>();
|
||||
for (Object producto : productos.values().toArray()) {
|
||||
listaProductosPrimerItem.add((Producto) producto);
|
||||
}
|
||||
listaProductosPrimerItem = Utils.ordenarBurbujaProductosPorPrecio(listaProductosPrimerItem);
|
||||
|
||||
System.out.println(listaProductosPrimerItem.getLast());
|
||||
break;
|
||||
case 3:
|
||||
List<Producto> listaProductos = new ArrayList<>();
|
||||
for (Object producto : productos.values().toArray()) {
|
||||
listaProductos.add((Producto) producto);
|
||||
}
|
||||
listaProductos = Utils.ordenarBurbujaProductosPorPrecio(listaProductos);
|
||||
|
||||
for (Producto p : listaProductos) {
|
||||
System.out.println(p.toString());
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
} while (opcion != 0);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user