Jason N.

asked • 12/10/20

Password requirement


Websites commonly require a password that satisfies several requirements. Write a program that checks if an input string satisfies the following (error message is shown for each):

  1. At least 8 characters (Too short)
  2. At least one letter (Missing letter)
  3. At least one number (Missing number)
  4. At least one of these special characters: !, #, % (Missing special)

Output OK, or all related error messages (in above order). If the input string is "Hello", the output is:

Too short
Missing number
Missing special

Hints:

  1. Declare a boolean variable for each requirement.
  2. Use a for loop to visit each character, setting the corresponding boolean to true if satisfied (length is done differently though).
  3. Use the functions Character.isLetter() and Character.isDigit() to detect if a character is a letter or a number.


import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);

/* Type your code here. */
}
}



Patrick B.

source code uploaded to RESOURCES section under this link
Report

12/10/20

1 Expert Answer

By:

Patrick B. answered • 12/10/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Jason N.

Main.java:20: error: invalid method declaration; return type required PasswordValidator() can you help me fix?
Report

12/10/20

Jason N.

there is an invalid method decleration for PasswordValidator();
Report

12/10/20

Patrick B.

Your silly template has the class named MAIN... while I called it Passwordvalidator.... do a global search and replace to change all instances of PasswordValidator to Main
Report

12/10/20

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.