Use the string input by the user as an argument to open file

Assignment Help Data Structure & Algorithms
Reference no: EM13315230

In this 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 don't 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).

Submission:
- Hand in your complete Java source code; and a copy of the results after running your program on given file
- Upload your source code to CMS
- Demonstrate your program to TA before/on the due day


Attachment:- Assignment.txt

Reference no: EM13315230

Questions Cloud

Compute the increase in the internal energy of the neon : Suppose a tank contains 737 m3 of neon (Ne) at an absolute pressure of 1.01 105 Pa, What is the increase in the internal energy of the neon
What are the u.s. tax consequences of liquidation : What are the U.S. tax consequences of liquidation for Winco and what is the maximum amount of income that Acme can allocate to its IC-DISC? (Assume combined taxable income equals the $400 of net income from qualifi ed export receipts.)
Calculate the mean-standard deviation and the coefficient : during construction of the surface layer of asphalt pavement, two samples where taken everyday to measure the asphalt content in the mix to ensure that it is within the specification limits. the target value was set at 5.5 percent with a tolerance..
What volume flow rate will keep pressures in the two pipes : A liquid is flowing through a horizontal pipe whose radius is 0.0186 m. What volume flow rate will keep the pressures in the two horizontal pipes
Use the string input by the user as an argument to open file : 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.
How much will bar deform if it is released from the framwork : A 24-in.-long copper bar with a yield strength of 30,000 psi is heated to 120°C and immediately fastened securely to a rigid framework. The coefficient of thermal expansion for copper is 16.6x10-6 (1/oC).
What is the electric field everywhere : A spherical, conducting shell (inner radius = a and outer radius = b) has a charge +Q placed on it. What is the electric field everywhere
What tension load is needed to return length to the original : a meter long steel plate with a rectangular cross section(10mm x 50mm) is resting on a frictionless surface under the sun. the plate temperature is measures to be at 40C.
What is the magnitudeof the force exerted on his back : the forces exerted on the shoes and back of the 72-kg climber bythe walls of the chimney are perpendicular to the walls exertingthem. what is the magnitudeof the force exerted on his back

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Design and implement an avl tree algorithm

Design and implement an AVL tree algorithm that searches a collection of documents. You will be provided with a set of 50 documents and a set of sample queries. First, you will process the documents and store their content (i.e. words / tokens) in..

  Find the first occurrence, the last occurrence

If numbers in a list aren't unique and therefore the largest number could occur more than once would the algorithm find the first occurrence, the last occurance? Every occurance?

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Program to create huffman codes

Write a C++ program to create Huffman codes. Program input is a file called freq.txt (make up your own file for testing) that contains data on the characters in some cleartext file in the form of each character's non-zero frequency of occurrence i..

  Formula to compute number of address bus conductors

If an address bus needs to be able to address 8-devices, how many conductors will be needed? What if each of those devices also requires to be able to talk back to the I/O control device?

  Explain solution of towers of hanoi problem

Classical Towers of Hanoi problem starts with a stack of n > = 1disks on one of three pegs. Solving problem needs moving stack from peg A to peg B in such a way which only one disc is moved at time and no disc can be placed on top of a disc smalle..

  Implement a nice graph datastructure

Implement a nice graph datastructure. Implement two different greedy graph coloring algorithms. Shortest path algorithm and MST algorithms.

  Complications in a time sharing system

Determine what complications could happen in a time-sharing system if two processes need access to the same file at the same time?

  The class linked bag did not have the data member itemcount

the class LinkedBag did not have the data member itemCount. Revise the method getCurrentSize so that it counts the number of nodes in the linked chain

  Question about lan and wan

Think about the following two scenarios two computers are connected to a LAN using a total of 20-feet of cable, and two computers are connected over the Internet and are 8000 miles from each other.

  Create tree correspond to expression pre-order traversal

Let the algebraic expression E=(2x+y)(5a-b)^3. Create tree T which correspond to expression E and determine pre-order traversal of T.

  What is difference between a state graph and a search tree

Describe how the problem of traveling from one city to another could be framed as a production system. What are the states? What are the productions?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd