word Problem (2s points) iddlesex County College has asked you to write a passwo
ID: 3596316 • Letter: W
Question
word Problem (2s points) iddlesex County College has asked you to write a password generator. Write a class named passwordGenerator that uses a Scanner object to read user input (Do not use JOptionPane). The Pass wordGenerator class does the following: 1)- Prints a welcome message with the string "WELCOME TO THE MCC PASSWORD GENERATOR" 2) - Prompts the user to enter a 3-character string. 3) - Validates the input to verify that exactly three characters were entered. 4) - Makes the user enter the string again if invalid. 5)-Prompts the user to enter one of the following punctuation characters:" , or %. 6) - Validates the input to verify that one of the punctation characters listed above was entered 7) - Makes the user enter the character again if invalid. 8) - Prompts the user to enter a number between 100 and 999. 9) - Validates the input to verify that the number was between 100 and 999. 10)- Makes the user enter the number again if invalid. 11)- Concatenates the string, punctuation character, and number into a password string. 12)- Prints a message containing the password string to the screen.
Explanation / Answer
import java.util.Scanner;
public class PasswordGenerator{
protected static void generatePassword(){
String password;
char symbol;
String charString;
int num;
System.out.println("WELCOME TO THE MCC PASSWORD GENERATOR");
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter a three character string");
while(true){
charString = scanner.nextLine();
if(charString.length() !=3){
System.out.println("Invalid String! Please enter a three character string");
}
else{
break;
}
}
while(true){
System.out.println("Please enter any one of the symbol : 1. .(full stop) 2. # (hash) 3. %(percentile) ");
symbol = scanner.next().charAt(0);
if(symbol == '.'|| symbol == '#' || symbol == '%' ){
break;
}
else{
System.out.println("Invalid Character");
}
}
while(true){
System.out.println("Please enter a number between 100 and 999 :");
num = scanner.nextInt();
if(num >= 100 && num <= 999){
break;
}
else{
System.out.println("Invalid number");
}
}
System.out.println("Genertaed password " +charString + symbol + num);
}
}
In the program I have created a class Password Generator as asked in que, with method generatedPassword as all functionalities of class is implemented using methods.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.