Question
In this Java assignment, you are to write a program that analyzes a selection of text, counting the number of times each word appears in
In this Java assignment, you are to write a program that analyzes a selection of text, counting the number of times each word appears in the text. Your word counts must ignore capitalization, so the, The, THE, and tHe all increase the count for the word the by one. For purposes of this assignment, a word is any consecutive string of letters and the apostrophe character, so dont counts as a single word, and best-selling counts as two words: best and selling. Notice that a blank space will not necessarily occur between two words. Numbers such as 27 and 2/3 will NOT be counted as words.
You must store the words and the counts of the words in a single binary search tree. Each word occurring in the text can only be stored once in the tree. Call the structure for the nodes of the tree WordNode, and call the references in this structure left and right. Use Strings to store words in the tree. Call the class implementing the binary search tree WordTree. It must contain the following public methods: constructors add: adds the given word to the tree if it is not already in the tree OR increments the appropriate counter if it is already there. It returns nothing. countNodes: returns the number of words currently stored in the tree. countWordsWith4Chars: returns the number of words which have exactly four characters. print: display the words of the tree in alphabetical order, and next to each word, prints the number of times each word occurs in the text.
Three of these operations (all but add) must visit every node in the tree. One of these must use preorder traversal, one must use inorder traversal, and one must use postorder traversal. You must decide which to use for each method, but use comments to document the type of traversal used.
The WordTree class may have only one data member variable, root, and it must be private.
Your program should perform the following steps:
1. Prompt the user for the name of the file (a string). Use the string input by the user as an argument to open file:
2. Open the file on disk, and process its contents, adding unique words to the BST and increasing the counts of existing words if necessary 3. Repeat steps 1&2 until the user enters some sentinel value.
4. Print out the total number of nodes in your tree 5. Print out the number of words which have exactly four characters. 6. print out the contents of a tree in alphabetical order Optional: if you have time, implement a method to delete every node from your BST that contains a word that is 3 or fewer letters long (note that you must explicitly make these deletions, not fail to insert these words in the first place).
Example text to be used
The alleged paradox begins with a sceptical inquiry about my right to claim that my past usage of '+' (i.e., my past usage of the plus sign) was used to denote the function plus rather than the function quus. The definition of quus is: x quus y = x + y, if x, y < 57; otherwise, x quus y = 5. (Kripke uses an encircled plus sign to represent the quus sign. I can't reproduce that sign here so I'll just use 'quus'). Basically, the problem is that on all of the problems that I have done so far, the plus and quus functions demand the same answers. So, whether I know it or not, my past responses to computations have been in accord with plus just as much as they have been in accord with quus. Thus, there seems to be no reason at all to prefer the claim that I've been plussing to the claim that I've been quussing, given my hypothetical past history. After all, the two functions are identical over the cases that I am allowed to appeal to so far. Given this setup, Kripke boldly asks: "Who is to say that [quus] is not the function I previously meant by '+'?" The sceptic claims that no one can legitimately claim that quus is not the function I previously meant by '+', given the hypothetical situation he proposes, because no one can find a fact that shows that I meant plus rather than quus. More specifically, the sceptic challenges those of us who disagree with him to produce a fact that shows that I meant plus rather than quus. Also, the sceptic requires that the fact in question "must, in some sense, show how I am justified in giving the answer '125' to '68 + 57'" (rather than '5'). (K, p. 11). (I have always seen the second form of the challenge, as Kripke calls it, viz., the requirement that the fact show how I am justified in answering '125' rather than '5', as simply a way of clarifying the task at hand. After all, challenging someone to produce a fact that I meant plus rather than quus is not the most obvious challenge in the world, for a variety of reasons. Since it's clear that if I such a fact could be produced, it would justify my saying '125' rather than '5', the second form of the challenge does not impose a new task on us. Rather, it clarifies the task to be performed).
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