Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Tried adding the file but it’s too big 11:59 PM The attached file, enable1. bxt

ID: 3909626 • Letter: T

Question

Tried adding the file but it’s too big
11:59 PM The attached file, enable1. bxt is the list of all words permissible to play in a Words with Friends game. It is sorted in alphabetical order, one word per line. All the words are lowercase. You are to write a program which will 1. Create an ArrayList to hold String objects 2 Read the file enable1.td into the array, counting the total number of words in the file. Use a method to do this. The method header should look lke this public statie void readkordt.ist (arrayList wordlist) 3. Close the input file Use the size mothod of the ArrayList to display the number of words in the fie 5. Ask the user input a word from the keyboard. 6 Convert the word to l 7. Use a method to on the wordlist to determine whether it is a valid Words with Friends word. The method will return true if the d is in the wordlist it returns false otherwise. The method header should look like this: public 8. Ask the user if he/she wishes to search for another word in the wordlist, and repeat from step 4 if so. Upload your solution (java file) to Blackboard make sure to click Submit lick Sare us Drujt chnges and continue working leter, When or ehick Caneel to quit without sacing changes CancelSavo D PrtScn Home End 2 9

Explanation / Answer

If you have any doubts, please give me comment...

import java.util.*;

import java.io.*;

public class WordList{

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

String choice;

ArrayList<String> wordlist = new ArrayList<>();

readWordList(wordlist);

System.out.println("Number of words in the file: "+wordlist.size());

do{

System.out.print("Enter word to search: ");

String word = in.next().toLowerCase();

System.out.println(word+" is in wordlist? "+binarySearch(wordlist, word));

System.out.print("Do you want to search another word(yes/no)? ");

choice = in.next();

}while(choice.equalsIgnoreCase(choice));

}

public static void readWordList(ArrayList<String> wordlist){

try{

Scanner fin = new Scanner(new File("enable1.txt"));

while(fin.hasNextLine()){

wordlist.add(fin.nextLine());

}

fin.close();

}catch(FileNotFoundException e){

System.out.println("Unable to open file");

}

}

public static boolean binarySearch(ArrayList<String> wordlist, String key){

int l = 0, r = wordlist.size()-1;

while (l <= r)

{

int m = l + (r-l)/2;

if (wordlist.get(m).equals(key))

return true;

if (wordlist.get(m).compareTo(key)<0)

l = m + 1;

else

r = m - 1;

}

return false;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote