- import java.io.*;
- import java.util.*;
- import java.text.*;
- import java.math.*;
- import java.util.regex.*;
- /authod:suneel sharma/
- public class LoginManager {
- public static void main(String args[] ) throws Exception {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- Login[] logins = new Login[5];
- Scanner sc = new Scanner(System.in);
- for(int i = 0;i<logins.length;i++)
- {
- String userid = sc.nextLine();
- String password = sc.nextLine();
- String location = sc.nextLine();
- // sc.nextLine();
- boolean accountLocked = Boolean.valueOf(sc.nextLine());
- logins[i]= new Login(userid,password,location,accountLocked);
- }
- String username = sc.nextLine();
- String newpassword = sc.nextLine();
- String loc = sc.nextLine();
- boolean val =changePassword(logins,
- username,
- newpassword);
- System.out.println(val);
- Login[] logs = getLockedUsers(logins,loc);
- if(logs.length>0) {
- for(Login log : logs) {
- if(log!=null) {
- System.out.println(log.getUsername()+" "+log.getPassword()+" "+log.getLocation());
- }
- }
- }else{
- System.out.println("Nothing Found");
- }
- }
- //please implement method1 & 2 here
- public static boolean changePassword(Login[] logins, String username, String password){
- boolean isChangedPwd =false;
- for(Login lg : logins){
- if(lg.getUsername().equalsIgnoreCase(username)){
- if(lg.getPassword().equalsIgnoreCase("ChangePwd@tcs123") && lg.isAccountLocked()!=true){
- lg.setPassword(password);
- return true;
- }
- }
- }
- return false;
- }
- public static Login[] getLockedUsers(Login[] logins, String location){
- int index=0,countType=0;
- for(Login pd : logins){
- if(pd.getLocation().equalsIgnoreCase(location) && pd.isAccountLocked()==true){
- countType++;
- }
- }
- Login[] lockedAccounts = new Login[countType];
- if(countType==0){
- return lockedAccounts;
- }
- for(Login pd : logins){
- if(pd.getLocation().equalsIgnoreCase(location) && pd.isAccountLocked()==true){
- lockedAccounts[index] = pd;
- index++;
- }
- }
- return lockedAccounts;
- }
- }
- class Login{
- //Create attributes, constructors, getters and setters
- private String username;
- private String password;
- private String location;
- private boolean accountLocked;
- public Login(String username, String password, String location, boolean accountLocked) {
- super();
- this.username = username;
- this.password = password;
- this.location = location;
- this.accountLocked = accountLocked;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getLocation() {
- return location;
- }
- public void setLocation(String location) {
- this.location = location;
- }
- public boolean isAccountLocked() {
- return accountLocked;
- }
- public void setAccountLocked(boolean accountLocked) {
- this.accountLocked = accountLocked;
- }
[text] jlogin
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: