Advertisement
Guest User

P01 Menu usuarios

a guest
Dec 7th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.03 KB | None | 0 0
  1. public static void main(String[] args) {
  2.         ArrayList<Usuario> Usuarios = new ArrayList<>();
  3.         boolean existe = false;
  4.  
  5.         int opcion;
  6.         Scanner xr = new Scanner(System.in);
  7.  
  8.         do {
  9.             System.out.println("---------------------------------------------------------------------");
  10.             System.out.println("Hola! Seleccione la opción del menu:"
  11.                     + "\n1. Añadir usuario"
  12.                     + "\n2. Eliminar usuario"
  13.                     + "\n3- Modificar usuario"
  14.                     + "\n4. Iniciar sesión"
  15.                     + "\n5. Imprimir usuarios"
  16.                     + "\n0. Salir");
  17.  
  18.             opcion = xr.nextInt();
  19.  
  20.             switch (opcion) {
  21.                 case 1:
  22.                     System.out.println("Ingrese el usuario añadir");
  23.  
  24.                     System.out.println("Ingrese el nombre: ");
  25.                     String nombre = xr.next();
  26.  
  27.                     System.out.println("Ingrese la contraseña");
  28.                     String contraseña = xr.next();
  29.  
  30.                     System.out.println("Ingrese el correo");
  31.                     String correo = xr.next();
  32.  
  33.                     Usuario a1 = new Usuario(nombre, contraseña, correo);
  34.                     System.out.println("Usuario creado con exito");
  35.                     Usuarios.add(a1);
  36.  
  37.                     break;
  38.                 case 2:
  39.  
  40.                     System.out.println("Ingresa el nombre del usuario a eliminar");
  41.                     String buscar = xr.next();
  42.  
  43.                     for (int i = 0; i < Usuarios.size(); i++) {
  44.                         if (Usuarios.get(i).getNombre().equals(buscar)) {
  45.                             Usuarios.remove(i);
  46.                             System.out.println("Usuario eliminado");
  47.                             break;
  48.                         }
  49.                     }
  50.  
  51.                     break;
  52.  
  53.                 case 3:
  54.                     System.out.println("Que usuario desea modificar");
  55.                     String nuevo = xr.next();
  56.  
  57.                     for (int i = 0; i < Usuarios.size(); i++) {
  58.  
  59.                         if (Usuarios.get(i).getNombre().equals(nuevo)) {
  60.  
  61.                             System.out.println("Ingrese el nuevo nombre: ");
  62.                             String nuevonombre = xr.next();
  63.  
  64.                             System.out.println("Ingrese la nueva contraseña");
  65.                             String nuevacontraseña = xr.next();
  66.  
  67.                             System.out.println("Ingrese el nuevo correo");
  68.                             String nuevocorreo = xr.next();
  69.  
  70.                             /*Usuario usuarioModificado = new Usuario(nuevonombre, nuevacontraseña, nuevocorreo);
  71.                            
  72.                             Usuarios.remove(i);
  73.                             Usuarios.add(i, usuarioModificado);*/
  74.                             Usuarios.get(i).setNombre(nuevonombre);
  75.                             Usuarios.get(i).setContrasena(nuevacontraseña);
  76.                             Usuarios.get(i).setCorreo(nuevocorreo);
  77.  
  78.                             System.out.println("Modificado exitosamente");
  79.                             break;
  80.                         }
  81.  
  82.                     }
  83.  
  84.                     break;
  85.                
  86.                 case 4:
  87.                     System.out.println("Ingresa correo");
  88.                     String usr = xr.next();
  89.                    
  90.                     System.out.println("Ingresa password");
  91.                     String pss = xr.next();
  92.                    
  93.                     for (int i = 0; i < Usuarios.size(); i++) {
  94.                         if(Usuarios.get(i).getCorreo().equals(usr)){
  95.                             existe = true;
  96.                            if(Usuarios.get(i).getContrasena().equals(pss)){
  97.                                 System.out.println("Bienvenido al sistema "+Usuarios.get(i).getNombre());
  98.                            }else{
  99.                                System.out.println("Contraseña incorrecta");
  100.                            }
  101.                         }
  102.                     }
  103.                    
  104.                     if(!existe){
  105.                         System.out.println("Correo no existente");
  106.                     }
  107.                     break;
  108.  
  109.                 case 5:
  110.  
  111.                     System.out.println("Los usuarios son: ");
  112.  
  113.                     for (int i = 0; i < Usuarios.size(); i++) {
  114.  
  115.                         System.out.println(" Nombre: " + Usuarios.get(i).getNombre()
  116.                                 + "  Contraseña: " + Usuarios.get(i).getContrasena()
  117.                                 + "  Correo: " + Usuarios.get(i).getCorreo()
  118.                         );
  119.  
  120.                     }
  121.                     break;
  122.                 case 0:
  123.                     System.out.println("Gracias por usar el sistema");
  124.                     break;
  125.                 default:
  126.                     System.out.println("Opción incorrecta");
  127.                     break;
  128.             }
  129.  
  130.         } while (opcion != 0);
  131.  
  132.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement