Copy the file CheckPassword.java to the directory
exercises/ex4 of your repository. This file contains the skeleton of a
small program to check the validity of a password. Your task is to
add the missing code to this skeleton.
For a password to be deemed valid, it should have a length of at least
twelve characters, and it should contain at least two digits. These two
checks should be performed by the static methods
atLeastTwoDigits(), respectively. Each method should return a value
true if the required condition is satisfied, or
false if it is not.
The password to be checked must come from the command line used to invoke the program. You should NOT prompt for input of the password once the program is actually running. Consult the Java Tutorials for an explanation of command line arguments if you are not sure how they work. After checking the password, the program should print a short message (see below), informing the user whether it is valid or not.
If no password has been provided on the command line, the program should print a usage message (see below) to the standard error stream and then terminate with a non-zero exit status code.
Here are examples of expected program behaviour:
$ java CheckPassword jkft45aa Password is not valid $ java CheckPassword axhpqwcn99pd Password is valid $ java CheckPassword Usage: java CheckPassword <password>
Make sure that your program generates exactly the same output as these examples.
Go to Submit My Work → Exercises 1-5 → Exercise 4 in Minerva to submit your solution for grading. Also, don’t forget to commit your work to your Git repository and push those commits up to GitLab.
Character type can be determined using the various static methods of the
Character class. For example,
Character.isDigit(c) will return
if the character
c is a digit,
false if it is not. See the
Character API documentation for further details.
System.err to print the usage message. This can be used in the
same way as
System.out. Remember that
System.exit() can be used to
terminate a running program.