Advertisement
gonzalob

Untitled

May 17th, 2022
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. package app;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.        
  9.         int cantidad = 1;
  10.         boolean rta = false;
  11.        
  12.         Scanner scanner = new Scanner(System.in);
  13.         while (!rta)
  14.        
  15.             {
  16.                 try
  17.                 {
  18.                     System.out.println("ingrese usuario");
  19.                     rta = login(scanner.nextLine(),"1223",cantidad);
  20.                    
  21.                 }
  22.                 catch (UsuarioIncorrecto ex)
  23.                 {
  24.                     //inicio flujo de olvide mi usuario
  25.                     cantidad++;
  26.                 }
  27.                 catch (PasswordIncorrecto e) {
  28.                     // TODO: handle exception
  29.                     //inicio flujo de olvide contraseña
  30.                    
  31.                     cantidad++;
  32.                 }
  33.                 catch (Exception e) {
  34.                     // TODO Auto-generated catch block
  35.                     System.out.println(e.getMessage());
  36.                    
  37.                 }
  38.         }
  39.        
  40.         //login2("pepe", "1234");
  41.    
  42.        
  43.     }
  44.    
  45.     public static boolean login(String usuario, String pass, int cantidad)
  46.             throws UsuarioIncorrecto, PasswordIncorrecto
  47.     {
  48.         if (!usuario.equals("admin"))
  49.         {
  50.             throw new UsuarioIncorrecto("no sos admin",cantidad);
  51.         }
  52.         if (!pass.equals("123"))
  53.         {
  54.             throw new PasswordIncorrecto("mal la contraseña");
  55.         }
  56.         return true;
  57.                
  58.     }
  59.    
  60.     public static void login2(String usuario, String pass)
  61.     {
  62.         try
  63.         {
  64.             if (!usuario.equals("admin"))
  65.             {
  66.                 throw new Exception("no sos admin");
  67.             }
  68.         }
  69.         catch (Exception e) {
  70.             System.out.println(e.getMessage());
  71.         }
  72.                
  73.     }
  74.    
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement