Necesito ayuda con la llamada de metodos :(
Publicado por Belen Andrea SanMartin (1 intervención) el 18/10/2018 22:55:36
este es mi programa y tengo un serio problema o confusión con la llamada de métodos con parámetros, si alguien lo puede corregir me ayudaría mucho

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
215
216
217
218
package tarea;
import java.util.Scanner;
public class Tarea {
public static void main(String[] args) {
menu(String[]hotel,int[]precios);
}
public static String[] hotel(){
String hotel[]=new String[10];
return hotel;
}
public static int[] precios(){
int precios[]=new int[10];
return precios;
}
public static void menu(String[]hotel,int[]precios){
int opc;
do{
System.out.println("Software de gestión hotelera");
System.out.println("1. Ingresar al hotel");
System.out.println("2. Mostrar informacion del hotel");
System.out.println("3. Salir");
opc = leerEntero();
switch (opc){
case 1: ingresar(String[]hotel,int[]precios);
break;
case 2: info(int[]precios);
break;
case 3: System.out.println("¡Adios!");break;
default: break;
}
}while(opc!=3);
}
public static void info(int[]precios){
for(int i=0;i<precios.length;i++){
System.out.println("la habitacion "+i+" paga "+precios[i]);
}
}
public static String leerString(){
Scanner leer = new Scanner(System.in);
String stri = leer.nextLine();
return stri;
}
public static int leerEntero(){
Scanner leer = new Scanner(System.in);
int num1 = leer.nextInt();
return num1;
}
public static void ingresar(String[]hotel,int[]precios){
boolean salir = false;
while(!salir){
System.out.println("==================================================");
System.out.println("Bienvenido al hotel 'donde cabe 1, caben 2'");
System.out.println("[1].-Pedir habitacion");
System.out.println("[2].-Reservar habitacion");
System.out.println("[3].-estado de las habitaciones");
System.out.println("[4].-reiniciar hotel");
System.out.println("[5].-Salir.");
System.out.println("==================================================");
int opcion = leerEntero();
switch(opcion){
case 1:{
pedirHabitacion(String[]hotel,int[]precios);
break;
}
case 2:{
reservarHabitacion(String[]hotel,int[]precios);
break;
}
case 3:{
espaciosDisponibles(String[]hotel);
espaciosOcupados(String[]hotel);
espaciosReservados(String[]hotel);
break;
}
case 4:{
reiniciar(String[]hotel);
break;
}
case 5:{
salir = true;
break;
}
}
}
}
public static String[] espaciosDisponibles(String[]hotel){
int contador =0;
for(int i=0;i<hotel.length;i++){
if(hotel[i] == "r"){
contador++;
}
}
System.out.println("hay "+contador+" habitaciones reservadas");
return hotel;
}
public static String[] espaciosOcupados(String[]hotel){
int contador =0;
for(int i=0;i<hotel.length;i++){
if(hotel[i] == "p"){
contador++;
}
}
System.out.println("hay "+contador+" habitaciones ocupadas");
return hotel;
}
public static String[] espaciosReservados(String[]hotel){
int contador =0;
for(int i=0;i<hotel.length;i++){
if(hotel[i] == null){
contador++;
}
}
System.out.println("el numero de espacios disponibles es: "+contador);
return hotel;
}
public static void pedirHabitacion(String[]hotel,int[]precios){
for(int i=0;i<10;i++){
if(hotel[i] == null){
hotel[i] = "p";
i=10;
}
}
System.out.println("tienes dos opciones \n'S' para sin desayuno y cena=$30.000 \n'C' para con desayuno y cena=$40.000");
String opci=null;
try{
opci=leerString();
}catch(Exception e){
System.out.println("ingrese un valor valido");
}
if(opci=="S"){
for(int i=0;i<10;i++){
if(precios[i] == 0){
precios[i] = 30000;
i=10;
}
}
}else if(opci=="C"){
for(int i=0;i<10;i++){
if(precios[i] == 0){
precios[i] = 40000;
i=10;
}
}
}
System.out.println("su pedido fue exitoso");
}
public static void reservarHabitacion(String[]hotel,int[]precios){
for(int i=0;i<10;i++){
if(hotel[i] == null){
hotel[i] = "r";
i=10;
}
}
System.out.println("tienes dos opciones \n'S' para sin desayuno y cena=$30.000 \n'C' para con desayuno y cena=$40.000");
String opci=null;
try{
opci=leerString();
}catch(Exception e){
System.out.println("ingrese un valor valido");
}
if(opci=="S"){
for(int i=0;i<10;i++){
if(precios[i] == 0){
precios[i] = 30000;
i=10;
}
}
}else if(opci=="C"){
for(int i=0;i<10;i++){
if(precios[i] == 0){
precios[i] = 40000;
i=10;
}
}
}
System.out.println("su pedido fue exitoso");
}
public static void reiniciar(String[]hotel){
boolean salir = false;
int contrareal=1234;
while(!salir){
System.out.println("==================================================");
System.out.println("[1].-reiniciar hotel");
System.out.println("[2].-Salir.");
System.out.println("==================================================");
int opcion=0;
try{
opcion=leerEntero();
}catch(Exception e){
System.out.println("ingrese un valor valido");
}
switch(opcion){
case 1:{
System.out.println("ingrese contraseña");
int contra=0;
try{
contra=leerEntero();
}catch(Exception e){
System.out.println("ingrese un valor valido");
}
if(contra==contrareal){
for(int i=0;i<10;i++){
hotel[i] = null;
}
}
}
case 2:{
salir = true;
break;
}
}
}
}
}
Valora esta pregunta


0