View the step-by-step solution to:

Develop a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of...


Develop a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the first character of the parameter is a letter. If it is not a letter, the method throws an Exception of type Exception with the message of: "This is not a word."

·  Develop a complete Java method called getWord that takes no parameters and returns a String. The method prompts the user for a word, and then calls the checkWord method you wrote in #1 above, passing as a parameter the word the user provided as input. Make sure the getWord method handles the Exception that may be thrown by checkWord.

·  Develop a complete Java method called writeFile that takes two parameters: an array of Strings (arrayToWrite) and a String (filename). The method writes the Strings in the array'ToWrite' array to a text file called filename (the parameter), with each String on a separate line.

·  Develop a complete Java method called readFile that takes a String as a parameter (filename) and returns an ArrayList of Strings (fileContents). The method reads the text file identified by the filename parameter and populates the ArrayList with an element for each line in the text file.

·  In your main method, do the following in the order specified:

1.    Call the getWord method you wrote in #2 above and print the result to the command line.

2.    Develop an array of Strings called testData and populate it with at least three elements.

3.    Call the writeFile method you wrote in #3 above passing the array you created in #5.2 and the String "data.txt".

4.    Call the readFile method you wrote in #4 above to read the file you wrote in #5.3. Assign the result of readFile to an ArrayList variable in main called fileContents.

5.    Develop a loop to print the contents of the fileContents ArrayList to the command line.

Top Answer

The result of the program is: Enter a word: 85 killa java.lang.Exception: This is not a word Enter a word: killa The word is... View the full answer

123.PNG

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online