[text] jlogin

Viewer

  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6. /authod:suneel sharma/
  7. public class LoginManager {
  8.     public static void main(String args[] ) throws Exception {
  9.         /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  10.           Login[] logins = new Login[5];
  11.            Scanner sc = new Scanner(System.in);
  12.             
  13.             for(int i = 0;i<logins.length;i++)
  14.             {
  15.                 String userid = sc.nextLine();
  16.                
  17.                 String password = sc.nextLine();
  18.                 String location = sc.nextLine();
  19.                // sc.nextLine();
  20.                 boolean accountLocked = Boolean.valueOf(sc.nextLine());
  21.                 logins[i]= new Login(userid,password,location,accountLocked);
  22.             }
  23.             String username = sc.nextLine();
  24.             String newpassword =  sc.nextLine();
  25.             String loc = sc.nextLine();
  26.             
  27.             boolean val =changePassword(logins, 
  28.                     username, 
  29.                    newpassword);
  30.             System.out.println(val);
  31.             Login[] logs = getLockedUsers(logins,loc);
  32.            
  33.             if(logs.length>0) {
  34.                 for(Login log : logs) {
  35.                       if(log!=null) {
  36.                           System.out.println(log.getUsername()+" "+log.getPassword()+" "+log.getLocation());
  37.                       }
  38.                   }
  39.             }else{
  40.                 System.out.println("Nothing Found");
  41.             }
  42.            
  43.         
  44.     }
  45.     
  46.     //please implement method1 & 2 here
  47.     public static boolean changePassword(Login[] logins, String username, String password){
  48.         boolean isChangedPwd =false;
  49.         for(Login lg : logins){
  50.             if(lg.getUsername().equalsIgnoreCase(username)){
  51.                 if(lg.getPassword().equalsIgnoreCase("ChangePwd@tcs123") && lg.isAccountLocked()!=true){
  52.                     
  53.                     lg.setPassword(password);
  54.                     return true;
  55.                 }
  56.             }
  57.         }
  58.     return false;    
  59.     }
  60.     
  61.     public static Login[] getLockedUsers(Login[] logins, String location){
  62.         
  63.         int index=0,countType=0;
  64.         for(Login pd : logins){
  65.             if(pd.getLocation().equalsIgnoreCase(location) && pd.isAccountLocked()==true){
  66.                 countType++;
  67.             }
  68.         }
  69.         Login[] lockedAccounts = new Login[countType];
  70.          if(countType==0){
  71.              return lockedAccounts;
  72.          }
  73.          
  74.         for(Login pd : logins){
  75.             if(pd.getLocation().equalsIgnoreCase(location) && pd.isAccountLocked()==true){
  76.                 lockedAccounts[index] = pd;
  77.                 index++;
  78.             }
  79.         }
  80.         
  81.         return lockedAccounts;
  82.     }
  83. }
  84.  
  85. class Login{
  86.     //Create attributes, constructors, getters and setters
  87.         private String username;
  88.     private String password;
  89.     private String location;
  90.     private boolean accountLocked;
  91.     public Login(String username, String password, String location, boolean accountLocked) {
  92.         super();
  93.         this.username = username;
  94.         this.password = password;
  95.         this.location = location;
  96.         this.accountLocked = accountLocked;
  97.     }
  98.     public String getUsername() {
  99.         return username;
  100.     }
  101.     public void setUsername(String username) {
  102.         this.username = username;
  103.     }
  104.     public String getPassword() {
  105.         return password;
  106.     }
  107.     public void setPassword(String password) {
  108.         this.password = password;
  109.     }
  110.     public String getLocation() {
  111.         return location;
  112.     }
  113.     public void setLocation(String location) {
  114.         this.location = location;
  115.     }
  116.     public boolean isAccountLocked() {
  117.         return accountLocked;
  118.     }
  119.     public void setAccountLocked(boolean accountLocked) {
  120.         this.accountLocked = accountLocked;
  121.     }

Editor

You can edit this paste and save as new:


File Description
  • jlogin
  • Paste Code
  • 29 Jan-2020
  • 3.93 Kb
You can Share it: