-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
131 lines (120 loc) · 5.38 KB
/
Copy pathMain.java
File metadata and controls
131 lines (120 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import java.util.Scanner;
/**
* PASO 4: Clase Main
*
* Menú interactivo de la tienda
*/
public class Main {
public static void main(String[] args) {
// PASO 4.1: Inicialización
// TODO: Tienda tienda = new Tienda();
// TODO: tienda.cargarInventario();
// TODO: Scanner scanner = new Scanner(System.in);
// TODO: boolean salir = false;
// PASO 4.2: Menú principal (while loop)
// PISTA: while (!salir) { ... }
// TODO: while (!salir) {
// TODO: System.out.println("\n=== TIENDA ONLINE ===");
// TODO: System.out.println("1. Ver catálogo");
// TODO: System.out.println("2. Agregar al carrito");
// TODO: System.out.println("3. Ver carrito");
// TODO: System.out.println("4. Eliminar del carrito");
// TODO: System.out.println("5. Comprar");
// TODO: System.out.println("6. Salir");
// TODO: System.out.print("Elige: ");
// PASO 4.3: Leer opción con validación
// PISTA: try-catch para NumberFormatException
// PISTA: usar Integer.parseInt(scanner.nextLine())
// TODO: try {
// TODO: int opcion = Integer.parseInt(scanner.nextLine());
// PASO 4.4: Switch para cada opción
// TODO: switch (opcion) {
// TODO: case 1:
// TODO: // Ver catálogo
// TODO: break;
// TODO: case 2:
// TODO: // Agregar al carrito
// TODO: break;
// TODO: case 3:
// TODO: // Ver carrito
// TODO: break;
// TODO: case 4:
// TODO: // Eliminar del carrito
// TODO: break;
// TODO: case 5:
// TODO: // Comprar (pedir descuento)
// TODO: break;
// TODO: case 6:
// TODO: salir = true;
// TODO: System.out.println("👋 Adiós");
// TODO: break;
// TODO: default:
// TODO: System.out.println("❌ Opción no válida");
// TODO: }
// TODO: } catch (NumberFormatException e) {
// TODO: System.out.println("❌ Debes ingresar un número");
// TODO: }
// TODO: }
// TODO: scanner.close();
}
// PASO 4.5: Métodos auxiliares (privados, estáticos)
// Método para caso 1: Ver catálogo
// TODO: private static void verCatalogo(Tienda tienda) {
// TODO: tienda.mostrarCatalogo();
// TODO: }
// Método para caso 2: Agregar al carrito
// PISTA: pide nombre del producto y cantidad
// PISTA: try-catch para IllegalArgumentException
// TODO: private static void agregarAlCarrito(Tienda tienda, Scanner scanner) {
// TODO: System.out.print("Nombre del producto: ");
// TODO: String nombre = scanner.nextLine();
// TODO: System.out.print("Cantidad: ");
// TODO: try {
// TODO: int cantidad = Integer.parseInt(scanner.nextLine());
// TODO: tienda.agregarAlCarrito(nombre, cantidad);
// TODO: } catch (NumberFormatException e) {
// TODO: System.out.println("❌ Cantidad debe ser un número");
// TODO: } catch (IllegalArgumentException e) {
// TODO: System.out.println("❌ " + e.getMessage());
// TODO: }
// TODO: }
// Método para caso 3: Ver carrito
// TODO: private static void verCarrito(Tienda tienda) {
// TODO: tienda.getCarrito().verCarrito();
// TODO: }
// Método para caso 4: Eliminar del carrito
// PISTA: muestra carrito primero
// PISTA: pide índice a eliminar
// TODO: private static void eliminarDelCarrito(Tienda tienda, Scanner scanner) {
// TODO: tienda.getCarrito().verCarrito();
// TODO: if (!tienda.getCarrito().estaVacio()) {
// TODO: System.out.print("Índice a eliminar (0-basado): ");
// TODO: try {
// TODO: int index = Integer.parseInt(scanner.nextLine());
// TODO: tienda.getCarrito().eliminarProducto(index);
// TODO: } catch (NumberFormatException e) {
// TODO: System.out.println("❌ Índice debe ser un número");
// TODO: }
// TODO: }
// TODO: }
// Método para caso 5: Comprar
// PISTA: muestra carrito
// PISTA: pide descuento (0 si no hay)
// PISTA: genera factura
// PISTA: vacía el carrito (crea nuevo)
// TODO: private static void comprar(Tienda tienda, Scanner scanner) {
// TODO: tienda.getCarrito().verCarrito();
// TODO: if (tienda.getCarrito().estaVacio()) {
// TODO: System.out.println("❌ Carrito vacío");
// TODO: return;
// TODO: }
// TODO: System.out.print("¿Descuento (%)? (0 si no hay): ");
// TODO: try {
// TODO: double descuento = Double.parseDouble(scanner.nextLine());
// TODO: tienda.generarFactura(descuento);
// TODO: tienda = new Tienda(); // Reinicia para nuevo carrito
// TODO: } catch (NumberFormatException e) {
// TODO: System.out.println("❌ Ingresa un número válido");
// TODO: }
// TODO: }
}