In this project you will be creating programs to read in words from a file and do some String manipulations on those words. You will be using your skills with strings, file i/o, and recursion. Be sure to follow each of the steps below carefully. If it says you read in from input.txt, you must read in from input.txt. Do not read in from otherFile.txt. If you have any questions about the requirements, just ask. (Assume every file is in the same working directory as your code files.)

1. You must create a new class called MyWord that stores 1 thing, a String. The MyWord class implements the Comparable interface. When you are comparing 2 MyWords, you are not allowed to use any of the built-in String compare methods . You are only allowed to use charAt and length. Your compareTo method must sort them in reverse alphabetical order. For instance, dog comes before cat. Capitalization does not matter. dog should come before Cat.

2. Create a class called SortTest. Read in all of the words in a file called input.txt. Each word will be separated by whitespace (i.e. a space, a tab or a newline character). Store those words into an array of MyWord objects. When you are finished, sort the array using the following method: Arrays.sort(...). Because you are implementing the Comparable interface, your words will sort automatically. When your words are sorted, output them to a file called output.txt separating each word by a space.

3. Create a class called AlmostPalTest. Read in all of the words in a file called dictionary.txt. Each word will be separated by whitespace (i.e. a space, a tab or a newline character). You must write a recursive method to determine if the word being read in is almost a palindrome. An almost palindrome is defined as a word that would be a palindrome if exactly 1 letter is changed. That new word doesn't necessarily have to be a word. For example, car is an almost palindrome. If you change the 'c' to an 'r' you have rar. rar is not a word but it is a palindrome. You must output all almost palindromes to a file called almostPalOutput.txt.

4. Create a class called Composition. Read in all of the words in a file called dictionary.txt. Each word will be separated by whitespace (i.e. a space, a tab or a newline character). You must read in all words and determine if a word can be created by concatenating two other words. For example, the word racecar can be created by concatenating race and car. All such possibilities must be output to a file in this format:

racecar:race car

In other words, you output the original word followed by a colon, followed by the first word, followed by a space and finally the second word. Each answer is on 1 line. All of these possibilities are output to a file called composed.txt. All of the original words must be in alphabetical order. In other words, racecar:race car shows up in the output after another:an other.

5. Create a class called CompositionTwo. Read in all of the words in a file called dictionary.txt. Each word will be separated by whitespace (i.e. a space, a tab or a newline character). You must read in all words and determine if a word can be created by concatenating three or more words. For example, the word disconsolateness can be created by concatenating disc, on, so and lateness. All such possibilities must be output to a file in this format:

disconsolateness:disc on so lateness

In other words, you output the original word followed by a colon, followed by each word that makes up the original separated by a space. Each answer is on 1 line. All of these possibilities are output to a file called composedMore.txt. This is a very difficult problem and you will almost certainly need to use recursion for this problem.

Hint: Remember a recursive method can have as many parameters as it needs to keep track of the "current state of the problem." Also, like in the previous problem, the final output is likely to be in alphabetical order.

Your solutions should run relatively fast. You are encouraged to use the built-in Arrays.sort and Arrays.binarySearch where necessary.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.