Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

2. Explain in English what the following FA accepts. 0 B 1 0 1 1 C

Answered: 1 week ago