Write a Java program that generates a password for each employee in a company us
ID: 3818148 • Letter: W
Question
Write a Java program that generates a password for each employee in a company using their name, surname and a special number entered by the user. Assuming a name has n characters and a surname has s characters, the password of each employee will be generated using the below rule: Password = First(n/2)CharactersOfName+ First(s/2)CharactersOfSurname +SpecialNumber+ (LastDigitOfSpeciatNumber^2): Traverse the employee list using a for-loop. For each employee: Name and surname will be entered as String. Special number will be entered as integer and its length cannot be larger than 6. You can use a while-loop for controlling this part. The strength information of the generated password will be kept in a corresponding variable (e.g. weak, medium, strong). A password within length range: [12] is considered to be strong. The number of passwords belong to each corresponding strength and the shortest (weakest)/longest (strongest) passwords should be printed at the end (see sample outputs). Enter the number of employees: Enter your name and surname: Enter your special number: The generated password for su as is: sa224 Weak password Password generator info dialog: # of weak passwords: 1 # of medium passwords: 0 # of strong passwords: 0 The weakest password is: sa224 The strongest password is: sa224Explanation / Answer
import java.util.*;
public class HelloWorld {
public static void main(String[] args) {
System.out.print("Enter the number of employees:");
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
String name;
String surname;
int specialnumber;
int specialnumber1;
String password;
int weak = 0;
int medium = 0;
int strong = 0;
String weakest = "subrahmanyam";
String strongest = null;
for(int i=0;i<a;i++){
System.out.println("Enter your name and surname:");
name = scan.next();
surname = scan.next();
while(true){
System.out.println("Enter your special number:");
specialnumber = scan.nextInt();
if((specialnumber/100000)<10){
specialnumber1 = specialnumber;
System.out.println(specialnumber1);
break;
}
else
System.out.println("enter 6 or less digit number");
}
password = name.substring(0,name.length() / 2) + surname.substring(0, surname.length() / 2) + specialnumber1 + (int) Math.pow((specialnumber1 % 10),2);
System.out.println("The generated password for " + name + " " + surname + " is: " + password);
if(password.length() < 7) {
System.out.println("Weak password");
weak++;
if(password.length() < weakest.length())
weakest = password;
}
else if(password.length() > 7 && password.length() < 13) {
System.out.println("Medium password");
medium++;
}
else {
System.out.println("Strong password");
strong++;
if(password.length() > strongest.length())
strongest = password;
}
}
System.out.println("Password generator info dialog:");
System.out.println("# of the weak passwords: " + weak);
System.out.println("# of the medium passwords: " + medium);
System.out.println("# of the strong passwords: " + strong);
System.out.println("The weakest of the password is: " + weakest);
System.out.println("The strongest of the password is: " + strongest);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.