Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- ArrayList<Usuario> Usuarios = new ArrayList<>();
- boolean existe = false;
- int opcion;
- Scanner xr = new Scanner(System.in);
- do {
- System.out.println("---------------------------------------------------------------------");
- System.out.println("Hola! Seleccione la opción del menu:"
- + "\n1. Añadir usuario"
- + "\n2. Eliminar usuario"
- + "\n3- Modificar usuario"
- + "\n4. Iniciar sesión"
- + "\n5. Imprimir usuarios"
- + "\n0. Salir");
- opcion = xr.nextInt();
- switch (opcion) {
- case 1:
- System.out.println("Ingrese el usuario añadir");
- System.out.println("Ingrese el nombre: ");
- String nombre = xr.next();
- System.out.println("Ingrese la contraseña");
- String contraseña = xr.next();
- System.out.println("Ingrese el correo");
- String correo = xr.next();
- Usuario a1 = new Usuario(nombre, contraseña, correo);
- System.out.println("Usuario creado con exito");
- Usuarios.add(a1);
- break;
- case 2:
- System.out.println("Ingresa el nombre del usuario a eliminar");
- String buscar = xr.next();
- for (int i = 0; i < Usuarios.size(); i++) {
- if (Usuarios.get(i).getNombre().equals(buscar)) {
- Usuarios.remove(i);
- System.out.println("Usuario eliminado");
- break;
- }
- }
- break;
- case 3:
- System.out.println("Que usuario desea modificar");
- String nuevo = xr.next();
- for (int i = 0; i < Usuarios.size(); i++) {
- if (Usuarios.get(i).getNombre().equals(nuevo)) {
- System.out.println("Ingrese el nuevo nombre: ");
- String nuevonombre = xr.next();
- System.out.println("Ingrese la nueva contraseña");
- String nuevacontraseña = xr.next();
- System.out.println("Ingrese el nuevo correo");
- String nuevocorreo = xr.next();
- /*Usuario usuarioModificado = new Usuario(nuevonombre, nuevacontraseña, nuevocorreo);
- Usuarios.remove(i);
- Usuarios.add(i, usuarioModificado);*/
- Usuarios.get(i).setNombre(nuevonombre);
- Usuarios.get(i).setContrasena(nuevacontraseña);
- Usuarios.get(i).setCorreo(nuevocorreo);
- System.out.println("Modificado exitosamente");
- break;
- }
- }
- break;
- case 4:
- System.out.println("Ingresa correo");
- String usr = xr.next();
- System.out.println("Ingresa password");
- String pss = xr.next();
- for (int i = 0; i < Usuarios.size(); i++) {
- if(Usuarios.get(i).getCorreo().equals(usr)){
- existe = true;
- if(Usuarios.get(i).getContrasena().equals(pss)){
- System.out.println("Bienvenido al sistema "+Usuarios.get(i).getNombre());
- }else{
- System.out.println("Contraseña incorrecta");
- }
- }
- }
- if(!existe){
- System.out.println("Correo no existente");
- }
- break;
- case 5:
- System.out.println("Los usuarios son: ");
- for (int i = 0; i < Usuarios.size(); i++) {
- System.out.println(" Nombre: " + Usuarios.get(i).getNombre()
- + " Contraseña: " + Usuarios.get(i).getContrasena()
- + " Correo: " + Usuarios.get(i).getCorreo()
- );
- }
- break;
- case 0:
- System.out.println("Gracias por usar el sistema");
- break;
- default:
- System.out.println("Opción incorrecta");
- break;
- }
- } while (opcion != 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement