Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Required Skills Inventory Declare and instantiate an ArrayList Write a method according to given specifications Write a method that returns an ArrayList Write a method
Required Skills Inventory
Declare and instantiate an ArrayList
Write a method according to given specifications
Write a method that returns an ArrayList
Write a method that takes an ArrayList as an argument
Open and read input from a text file
Use a Scanner to read input from a text file
Use String methods to identify and compare specific character in a String
Implement a simple linear search over a collection
Compose a program out of simple methods
Problem Description
For this project you will construct a program that will search a list for words that match a specified pattern. For example, given the following list of words:
amble
apple
box
echoes
fox
school
tumble
and the pattern:
cho
the program will find and print out:
echoes school
Note that the only words in the list of seven words above that match the pattern cho are echoes and school. These two words match the pattern because the pattern specifies a six letter word that has the letters c h and o as the second, third, and fourth letters. In the pattern, an underscore specifies any single letter.
c h o
e c h o e s
s c h o o l
The project can be broken down into the following methods:
getWordListString : ArrayList The purpose of this public static method is to open a text file containing a list of words and return an ArrayList that contains all the words in the file. This method should be defined to throw a FileNotFoundException using the throws keyword. Later, this ArrayList will be searched to find words that match a specified pattern.
When called and passed a file name like "words.txt this method will declare and instantiate a new ArrayList, then open the specified text file. The method will then read in each word in the file and add each word to the ArrayList. After all words have been read and added this method will return the ArrayList.
Note: The file will always contain a list of words with one word on each line, and each line ending with a newline
character.
Hint: The Scanner constructor method throws a FileNotFoundException when attempting to access a file.
isMatchAtIndexString String, int : boolean A public static method that when called and passed a word String and a pattern String and an index int the method will determine if the character at the index in the pattern is a match for the character at the same index in the word. The method will return true if the characters are a match, otherwise it will return false.
Example
isMatchAtIndexschoolcho would return true because the character at index in the pattern choh is an exact match for the character at index in the word "school".
Example
isMatchAtIndexschoolchi would return false because the character at index in the pattern chii is not a match for the character at index in the word "school" o
Example
isMatchAtIndexschoolcho would return true because the character at index in the pattern cho is an underscore and an underscore is a match for any character.
Example
isMatchAtIndexschoolcho would return false because there is no character at index in the pattern cho
isMatchString String : boolean A public static method that when called and passed a word String and a pattern String will determine if the specified word matches the specified pattern. The method will return true if the word and pattern match, otherwise it will return false.
Note that if a word does match a pattern, it is because isMatchAtIndexword pattern, index returns true for each index.
Example
isMatchschoolcho would return true because all character in the pattern match the character at the same index in the word. Remember that an underscore character in the pattern matches any letter at that same index in the word.
Example
isMatchschoolchi would return false because the character at index in the pattern chii is not a match for the character at index in the word "school" o and therefore the word "school" does not match the pattern chi
Example
isMatchappleap would return false because the word and the patter are not the same length, so they cannot be a match.
getMatchesArrayList String : ArrayList Write a public static method named getMatches. This method will take an ArrayList as its first argument and a String as its second argument. The method will return an Arraylist. When called and passed an word list ArrayList and a pattern String the method will find all of the words in the word list that match the specified pattern, add these to a new ArrayList, and then return this new ArrayList.
Given an ArrayList named wordList that contains the following words:
amble
apple
box
echoes
fox
school
tumble
Example
getMatcheswordListcho woul
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started