Error while loop
Publicado por Iwry (3 intervenciones) el 03/10/2019 17:57:26
Hola, estoy intentando desarollar un programa que para cargar compras (1 o varias) y no sé porque me cae en un loop.
Alguien podría ayudarme a encontrar el error?
Muchas gracias!
Alguien podría ayudarme a encontrar el error?
Muchas gracias!
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package paquete;
import java.util.Scanner;
public class queMePongo {
public static Scanner lector = new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method stub
int codCli;
String articulo;
String otroArt="SI";
int cant;
int desc;
double valorArt;
double importeVenta=0;
double acumVentas=0;
double descuentoValor;
double acumDesc=0;
double importeAPagarParc;
double importeAPagar=0;
double valClienteMax=0;
int codClienteMax=0;
codCli=ingCli("Ingrese el código de cliente (mayor a 0):");
// Empiezo el primer while
while (!(codCli<0)) {
articulo=ingArt("Ingrese el artículo (A1 - Remera / A2 - Buzo / A3 - Pantalón)");
// Empiezo el segundo while
while (otroArt=="SI") {
cant=ingCant("Ingrese la cantidad:");
desc=azar(1,5);
valorArt=obtenerImporteArt(articulo);
importeVenta=valorArt*cant;
acumVentas+=importeVenta;
descuentoValor=obtenerDescuentoCompra(importeVenta, desc);
acumDesc+=descuentoValor;
importeAPagarParc=importeVenta-descuentoValor;
importeAPagar+=importeAPagarParc;
if (valClienteMax==importeAPagar) {
codClienteMax=codCli;
}
valClienteMax=compararMax(valClienteMax, importeAPagar);
mostrarSubtotal(articulo, cant, importeVenta, descuentoValor, importeAPagar);
otroArt=preguntaOtroArt("Desea ingresar otro artículo? SI o NO:");
System.out.println(otroArt);
if (otroArt=="SI") {
articulo=ingArt("Ingrese el artículo (A1 - Remera / A2 - Buzo / A3 - Pantalón)");
}
}
// Finalizo el segundo while
codCli=ing2Cli("Ingrese el código de cliente (mayor a 0) o 0 para finalizar:");
// Finalizo el primer while
}
// Muestro resultado final
mostrarTotales(acumVentas, valClienteMax, codClienteMax, acumDesc);
}
// FX AZAR
private static int azar(int tope, int base){
// GENERA VALORES AL AZAR QUE SERIA LO QUE ELIGE LA MAQUINA
int result;
result=(int)((Math.random())*(tope+1-base))+base;
return result;
}
// FX ingCli
private static int ingCli(String mensaje){
int cod=0;
do {
System.out.println(mensaje);
cod=lector.nextInt();
lector.nextLine();
} while (cod<=0);
return cod;
}
// FX ing2Cli
private static int ing2Cli(String mensaje){
int cod=0;
do {
System.out.println(mensaje);
cod=lector.nextInt();
lector.nextLine();
} while (cod<0);
return cod;
}
// FX ingArt
private static String ingArt(String mensaje){
String art="";
do {
System.out.println(mensaje);
art=lector.nextLine();
} while (art=="A1"||art=="A2"||art=="A3");
return art;
}
// FX pregunaOtroArt
private static String preguntaOtroArt(String mensaje){
String otro="";
do {
System.out.println(mensaje);
otro=lector.nextLine();
} while (otro=="SI"||otro=="NO");
return otro;
}
// FX ingCant
private static int ingCant(String mensaje){
int cant=0;
do {
System.out.println(mensaje);
cant=lector.nextInt();
lector.nextLine();
} while (cant<=0);
return cant;
}
// FX obtenerImporteArt
private static double obtenerImporteArt(String articulo){
double valor=0;
switch (articulo) {
case "A1":
valor=200;
break;
case "A2":
valor=300;
break;
case "A3":
valor=400;
break;
default:
break;
}
return valor;
}
// FX obtenerDescuentoCompra
private static double obtenerDescuentoCompra(double importeVenta, int desc){
double valor=0;
switch (desc) {
case 1:
valor=importeVenta*0.1;
break;
case 2:
valor=importeVenta*0.2;
break;
case 3:
valor=importeVenta*0.3;
break;
case 4:
valor=importeVenta*0.4;
break;
case 5:
valor=importeVenta*0.5;
break;
default:
break;
}
return valor;
}
// FX compararMax
private static double compararMax(double valClienteMax, double importeAPagar){
double valor=0;
if (importeAPagar>=valClienteMax) {
valor=importeAPagar;
} else {
valor=valClienteMax;
}
return valor;
}
// FX mostrarSubtotal
private static void mostrarSubtotal(String articulo, int cant, double importeVenta, double descuentoValor, double importeAPagar){
System.out.println("==========================================================================");
System.out.println(" RESUMEN DEL ARTICULO");
System.out.println("==========================================================================");
System.out.println("Seleccionaste "+cant+" und. del artículo "+articulo+".");
System.out.println("El valor subtotal es: "+importeVenta);
System.out.println("Por sorteo obtuviste un descuento de: $"+descuentoValor);
System.out.println("==========================================================================");
System.out.println("El valor total a pagar es de: $"+importeAPagar);
System.out.println("==========================================================================");
}
// FX mostrarTotales
private static void mostrarTotales(double acumVentas, double valClienteMax, int codClienteMax, double acumDesc){
System.out.println("==================================================================================");
System.out.println(" INFORME FINAL");
System.out.println("==================================================================================");
System.out.println("El valor bruto total de ventas es de: $"+acumVentas);
System.out.println("El valor total de descuentos concedidos fue de: $"+acumDesc);
System.out.println("El cliente que tuvo la compra más cara fue el: "+codClienteMax);
System.out.println("El valor de su compra fue de: $"+valClienteMax);
System.out.println("==================================================================================");
}
}
Valora esta pregunta


0