Java - Me ayudan hacerle un par de arreglos a mi programa (Ascensor).

 
Vista:
sin imagen de perfil
Val: 10
Ha aumentado su posición en 2 puestos en Java (en relación al último mes)
Gráfica de Java

Me ayudan hacerle un par de arreglos a mi programa (Ascensor).

Publicado por Erick (41 intervenciones) el 16/06/2015 05:31:19
Necesito agregarle 2 cosas al programa:

1:Mensaje que diga "1 para cerrar la puerta del ascensor " cuando ya se le a indicado a que piso quiero ir y cuando llegue también pida "1 para abrir la puerta del ascensor " De lo contrario un mensaje que diga "Cierra el ascensor"
2:Que ya no sea de 10 pisos si no que la persona pueda cambiar esto a su gusto al iniciar el programa.



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
import java.util.Scanner;
 
public class Elevador {
 
    public static void main(String[] argv) {
        final String Mensaje_Error = "Seleccione un piso entre el 1 el 10 ";
        final int MAXIMO_MOVIMIENTO = 10;
        final int INICIO_PISO = 1;
        final int FINAL_PISO = 10;
        int PISOS = INICIO_PISO;
        int Movimiento = 0;
        int ir_al_piso;
        int Direccion;
        Scanner input = new Scanner(System.in);
        while (Movimiento < MAXIMO_MOVIMIENTO) {
            System.out.print("¿A que piso quiere ir?[" + INICIO_PISO + ".." + FINAL_PISO + "]? ");
            ir_al_piso = input.nextInt();
            while (ir_al_piso < INICIO_PISO || ir_al_piso > FINAL_PISO) {
                System.out.println(Mensaje_Error);
 
                System.out.print("¿A que piso quiere ir?[" + INICIO_PISO + ".." + FINAL_PISO + "]? ");
                ir_al_piso = input.nextInt();
            }
            if (ir_al_piso == PISOS) {
                System.out.println("No va a ningun piso...");
            } else {
                Movimiento++;
                if (ir_al_piso > PISOS) {
                    Direccion = 1;
                    System.out.print("Subiendo...");
                } else {
                    Direccion = -1;
                    System.out.print("Bajando...");
                }
                for (PISOS += Direccion;
                        ir_al_piso != PISOS;
                        PISOS += Direccion) {
                    System.out.print(PISOS + "...");
                }
                System.out.println("LLego a su destino " + PISOS);
            }
        }
        System.out.println("");
        System.exit(0);
    }
}


Por favor necesito un poco de ayuda: Ya lo he dañado varias veces por tratar de agregarle esto. GRACIAS
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 10
Ha aumentado su posición en 2 puestos en Java (en relación al último mes)
Gráfica de Java

Me ayudan hacerle un par de arreglos a mi programa (Ascensor).

Publicado por Erick (41 intervenciones) el 16/06/2015 08:20:52
OK ya pude solucionar el numero de pisos pero los mensajes de abrir y cerrar el ascensor aun no podrían por favor ayudarmen.



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
import java.util.Scanner;
 
public class Elevador {
 
    Scanner teclado;
    String[] Nombres;
    int cantidad;
 
    public static void main(String[] argv) {
        final String Mensaje_Error = "Seleccione un piso entre el 1 el 10 ";
        final int MAXIMO_MOVIMIENTO = 10;
        final int INICIO_PISO = 1;
        int PISOS = INICIO_PISO;
        int Movimiento = 0;
        int ir_al_piso;
        int Direccion;
        Scanner input = new Scanner(System.in);
        Scanner teclado;
        String[] Nombres;
        int cantidad;
        teclado = new Scanner(System.in);
        System.out.print("Ingrese la cantidad de pisos del edificio:");
        cantidad = teclado.nextInt();
        Nombres = new String[cantidad];
        while (Movimiento < MAXIMO_MOVIMIENTO) {
            System.out.print("¿A que piso quiere ir?[" + INICIO_PISO + ".." + cantidad + "]? ");
            ir_al_piso = input.nextInt();
            while (ir_al_piso < INICIO_PISO || ir_al_piso > cantidad) {
                System.out.println(Mensaje_Error);
 
                System.out.print("¿A que piso quiere ir?[" + INICIO_PISO + ".." + cantidad + "]? ");
                ir_al_piso = input.nextInt();
            }
            if (ir_al_piso == PISOS) {
                System.out.println("Esta en ese mismo piso pendejo...");
            } else {
                Movimiento++;
                if (ir_al_piso > PISOS) {
                    Direccion = 1;
                    System.out.print("Subiendo...");
                } else {
                    Direccion = -1;
                    System.out.print("Bajando...");
                }
                for (PISOS += Direccion;
                        ir_al_piso != PISOS;
                        PISOS += Direccion) {
                    System.out.print(PISOS + "...");
                }
                System.out.println("LLego a su destino " + PISOS);
            }
        }
 
        System.out.println(
                "");
        System.exit(
                0);
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 10
Ha aumentado su posición en 2 puestos en Java (en relación al último mes)
Gráfica de Java

Me ayudan hacerle un par de arreglos a mi programa (Ascensor).

Publicado por Erick (41 intervenciones) el 16/06/2015 16:40:28
Bueno lo termine pero no pude hacer que fuera con 1 para cerrar y abrir la puerta del ascensor, lo hice con mensajes jeje.

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
import javax.swing.JOptionPane;
import java.util.Scanner;
 
public class Elevador {
 
    public static void main(String[] argv) {
        String[] Nombres2;
        int cantidad2;
        final int INICIO_PISO = 1;
        int PISOS = INICIO_PISO;
        int Movimiento = 0;
        int ir_al_piso;
        int Direccion;
        Scanner input = new Scanner(System.in);
        Scanner teclado;
        String[] Nombres;
        int cantidad;
        teclado = new Scanner(System.in);
        System.out.print("Ingrese la cantidad de veces que utilizara el gravi ascensor Ericksson:");
        cantidad2 = teclado.nextInt();
        System.out.print("Ingrese la cantidad de pisos del edificio:");
        cantidad = teclado.nextInt();
        Nombres = new String[cantidad];
        final String Mensaje_Error = "No se quiera pasar de berga,Seleccione un piso entre el 1 a " + cantidad;
        while (Movimiento < cantidad2) {
            System.out.print("¿A que piso quiere ir? del [" + INICIO_PISO + " al " + cantidad + "]? ");
            ir_al_piso = input.nextInt();
            while (ir_al_piso < INICIO_PISO || ir_al_piso > cantidad) {
                System.out.println(Mensaje_Error);
                System.out.print("¿A que piso quiere ir? del [" + INICIO_PISO + " al " + cantidad + "]? ");
                ir_al_piso = input.nextInt();
            }
            if (ir_al_piso == PISOS) {
                System.out.println("Esta en ese mismo piso pendejo...");
            } else {
                Movimiento++;
                if (ir_al_piso > PISOS) {
                    Direccion = 1;
                    JOptionPane.showMessageDialog(null, "¡El ascensor se cerrara automaticamente!");
                    JOptionPane.showMessageDialog(null, "¡Cerrado!");
                    System.out.print("Subiendo...");
                    JOptionPane.showMessageDialog(null, "¡El ascensor se abrira automaticamente!");
                } else {
                    Direccion = -1;
                    JOptionPane.showMessageDialog(null, "¡El ascensor se cerrara automaticamente!");
                    JOptionPane.showMessageDialog(null, "¡Cerrado!");
                    System.out.print("Bajando...");
                    JOptionPane.showMessageDialog(null, "¡El ascensor se abrira automaticamente!");
                }
                for (PISOS += Direccion;
                        ir_al_piso != PISOS;
                        PISOS += Direccion) {
                    System.out.print(PISOS + "...");
                }
                System.out.println("LLego a su destino " + PISOS);
                JOptionPane.showMessageDialog(null, "¡Abierto!");
            }
        }
        System.out.println("Gracias por utilizar el Gravi Ascensor Ericksson");
        System.exit(0);
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar