Question: Coded in Java. c) you will write a setter method that assigns another string to the instance variable password, providing it meets the rules for

Coded in Java.

c) you will write a setter method that assigns another string to the instance variable password, providing it meets the rules for a valid password. In preparation for this, you will now write some methods that test some rules about valid passwords.

i. A valid password must have a length of at least 8 characters. Write a public instance method isValidLength(String pw) that returns true if pw is at least 8 characters long, and otherwise returns false.

ii. Strings have a charAt() method that you will need to use for the next part. In your own words, explain briefly what the charAt() method does.

iii. A valid password must include

- At least one uppercase letter

- At least one of the digits 0-9

The method below shows one way of checking if a string contains a digit. It uses a class method from the Character class, which checks if a character is a digit. A character is one of the standard Java classes and does not have to be imported.

https://pastebin.com/A8ZTCP0r - Java Method hasDigit(String pw)

Begin by copying this method into your class.

Then use it as a pattern to write a public instance method hasUpperCase(String pw) that returns true if the argument contains at least one uppercase character, otherwise returns false. Your method should use the method Character.isUpperCase().

iv. Write a public instance method isValidPassword(String pw) that accepts a string and checks if it meets all three of the rules described above. The method should return true if the argument string pw represents a valid password, and otherwise return false

Your method must make appropriate reuse of the methods you have written in (c)(i), the method given in (c) (iii) and the method you wrote in (c)(iii). That was the reason for writing them, so that they can be used whenever we need to check the password rules.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!