-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestaurante.java
More file actions
161 lines (147 loc) · 6.9 KB
/
Copy pathRestaurante.java
File metadata and controls
161 lines (147 loc) · 6.9 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import java.util.ArrayList;
import java.nio.file.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* PASO 3: Clase Restaurante
*
* Gestiona el menú, pedidos y ventas
*/
public class Restaurante {
// PASO 3.1: Atributos
// TODO: private ArrayList<Plato> menu;
// TODO: private ArrayList<Pedido> pedidos;
// TODO: private int contadorPedidos;
// PASO 3.2: Constructor
// TODO: public Restaurante() {
// TODO: menu = new ArrayList<>();
// TODO: pedidos = new ArrayList<>();
// TODO: contadorPedidos = 0;
// TODO: }
// PASO 3.3: cargarMenu()
// PISTA: crea 8-10 platos con categorías: Entrantes, Platos, Bebidas, Postres
// TODO: public void cargarMenu() {
// TODO: menu.add(new Plato(1, "Ensalada Mixta", "Entrantes", 8.50));
// TODO: menu.add(new Plato(2, "Tabla de Quesos", "Entrantes", 12.00));
// TODO: menu.add(new Plato(3, "Salmón a la Mantequilla", "Platos", 18.50));
// TODO: menu.add(new Plato(4, "Pasta Carbonara", "Platos", 14.00));
// TODO: menu.add(new Plato(5, "Filete de Res", "Platos", 22.00));
// TODO: menu.add(new Plato(6, "Agua 500ml", "Bebidas", 2.50));
// TODO: menu.add(new Plato(7, "Vino Tinto", "Bebidas", 15.00));
// TODO: menu.add(new Plato(8, "Tiramisú", "Postres", 7.50));
// TODO: menu.add(new Plato(9, "Mousse de Chocolate", "Postres", 8.00));
// TODO: System.out.println("✅ Menú cargado");
// TODO: }
// PASO 3.4: mostrarMenu()
// TODO: public void mostrarMenu() {
// TODO: System.out.println("=== MENÚ COMPLETO ===");
// TODO: for (Plato p : menu) {
// TODO: System.out.println(p.getInfo());
// TODO: }
// TODO: }
// PASO 3.5: mostrarPorCategoria()
// TODO: public void mostrarPorCategoria(String categoria) {
// TODO: System.out.println("=== " + categoria.toUpperCase() + " ===");
// TODO: for (Plato p : menu) {
// TODO: if (p.getCategoria().equalsIgnoreCase(categoria)) {
// TODO: System.out.println(p.getInfo());
// TODO: }
// TODO: }
// TODO: }
// PASO 3.6: buscarPlato()
// TODO: public Plato buscarPlato(String nombre) {
// TODO: for (Plato p : menu) {
// TODO: if (p.getNombre().equalsIgnoreCase(nombre)) {
// TODO: return p;
// TODO: }
// TODO: }
// TODO: return null;
// TODO: }
// PASO 3.7: crearPedido()
// TODO: public Pedido crearPedido() {
// TODO: contadorPedidos++;
// TODO: return new Pedido(contadorPedidos);
// TODO: }
// PASO 3.8: agregarAlPedido()
// TODO: public void agregarAlPedido(Pedido pedidoActual, String nombre, int cantidad) throws IllegalArgumentException {
// TODO: Plato p = buscarPlato(nombre);
// TODO: if (p == null) {
// TODO: throw new IllegalArgumentException("Plato no encontrado");
// TODO: }
// TODO: pedidoActual.agregarItem(p, cantidad);
// TODO: }
// PASO 3.9: confirmarPedido()
// TODO: public int confirmarPedido(Pedido pedido) throws IllegalArgumentException {
// TODO: if (pedido.estaVacio()) {
// TODO: throw new IllegalArgumentException("No puedes confirmar un pedido vacío");
// TODO: }
// TODO: pedidos.add(pedido);
// TODO: System.out.println("✅ Pedido #" + pedido.getId() + " confirmado");
// TODO: return pedido.getId();
// TODO: }
// PASO 3.10: mostrarPedidosPendientes()
// TODO: public void mostrarPedidosPendientes() {
// TODO: System.out.println("=== PEDIDOS PENDIENTES ===");
// TODO: boolean hay = false;
// TODO: for (Pedido p : pedidos) {
// TODO: if (p.getEstado().equals("pendiente")) {
// TODO: System.out.println("Pedido #" + p.getId() + " - Estado: " + p.getEstado());
// TODO: hay = true;
// TODO: }
// TODO: }
// TODO: if (!hay) System.out.println("📭 No hay pedidos pendientes");
// TODO: }
// PASO 3.11: cambiarEstadoPedido()
// TODO: public void cambiarEstadoPedido(int idPedido, String nuevoEstado) {
// TODO: for (Pedido p : pedidos) {
// TODO: if (p.getId() == idPedido) {
// TODO: p.cambiarEstado(nuevoEstado);
// TODO: return;
// TODO: }
// TODO: }
// TODO: System.out.println("❌ Pedido no encontrado");
// TODO: }
// PASO 3.12: generarCuenta()
// TODO: public void generarCuenta(int idPedido, double porcentajePropina) {
// TODO: for (Pedido p : pedidos) {
// TODO: if (p.getId() == idPedido) {
// TODO: double subtotal = p.calcularSubtotal();
// TODO: double propina = subtotal * porcentajePropina / 100;
// TODO: double total = subtotal + propina;
// TODO:
// TODO: System.out.println("\n========== CUENTA ==========");
// TODO: System.out.println("Pedido #" + idPedido);
// TODO: System.out.println("Subtotal: " + String.format("%.2f", subtotal) + "€");
// TODO: if (porcentajePropina > 0) {
// TODO: System.out.println("Propina (" + porcentajePropina + "%): " + String.format("%.2f", propina) + "€");
// TODO: }
// TODO: System.out.println("TOTAL: " + String.format("%.2f", total) + "€");
// TODO: System.out.println("===========================\n");
// TODO:
// TODO: guardarCuenta(idPedido, subtotal, propina, total);
// TODO: p.cambiarEstado("listo");
// TODO: return;
// TODO: }
// TODO: }
// TODO: System.out.println("❌ Pedido no encontrado");
// TODO: }
// PASO 3.13: guardarCuenta() (privado)
// TODO: private void guardarCuenta(int idPedido, double subtotal, double propina, double total) {
// TODO: try {
// TODO: LocalDateTime ahora = LocalDateTime.now();
// TODO: String timestamp = ahora.format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss"));
// TODO: String nombre = "venta_" + timestamp + ".txt";
// TODO:
// TODO: String contenido = "=== VENTA PEDIDO #" + idPedido + " ===\n" +
// TODO: "Subtotal: " + String.format("%.2f", subtotal) + "€\n" +
// TODO: "Propina: " + String.format("%.2f", propina) + "€\n" +
// TODO: "TOTAL: " + String.format("%.2f", total) + "€\n";
// TODO:
// TODO: Path path = Paths.get(nombre);
// TODO: Files.write(path, contenido.getBytes(), StandardOpenOption.CREATE);
// TODO: System.out.println("✅ Cuenta guardada: " + nombre);
// TODO: } catch (Exception e) {
// TODO: System.out.println("❌ Error: " + e.getMessage());
// TODO: }
// TODO: }
}