Question: Create a new class called ForbiddenWords. ForbiddenWords contains two instance variables, an ArrayList of String, and a Scanner. ForbiddenWords contains a single constructor which accepts

Create a new class called ForbiddenWords. ForbiddenWords contains two instance

variables, an ArrayList of String, and a Scanner.

ForbiddenWords contains a single constructor which accepts a single String as a

parameter. The String is the name of the file that contains the list of forbidden words. The constructor should:

i. Instantiate the ArrayList of String ii. Instantiate the Scanner. Instead of reading from System.in, we want to read

from a new File whose name is the String passed to the constructor. Your constructor should contain a line of code that looks like this:fileScanner = new Scanner(new File(fileName));

iii. Use a while loop and the Scanners hasNext method to loop through the list of words and add each one to the ArrayList of String.

Forbidden words contains a single public method called containsWord. It accepts a String, and returns true if the String is in the list of forbidden words, else it returns false.

10. Modify PasswordValidator so that it has a ForbiddenWords instance variable. Initialize the ForbiddenWords object inside the PasswordValidator start method. Pass in the name of your word list. For example, mine looks like this:

wordlist = new ForbiddenWords("src/ca/bcit/comp1510/lab9/words.txt");11. Modify your PasswordValidators event handler so that it uses the ForbiddenWords

object to ensure the potential password does not contain any of the forbidden Strings.

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!