Write a program findanagrams that reads words txt

Assignment Help Programming Languages
Reference no: EM131316530

Programming Project Sorting to find anagrams

See Project 4 on pg. 869 for the basic ideas of this project. We will find the longest anagrams in the words.txt provided in the Chapter 13 files on the author's website.

1. First we need to compute the canonical form of each word. The canonical form of a word contains the same letters as the original, but in sorted order. So compose a static method

public static String canonicalForm(String word)

so that canonicalForm("computer") returns "cemoprtu", and canonicalForm("poor") returns "oopr". For this first step, put this method in a little program CanonWord.java that inputs one word and outputs its canonical form:

java CanonWord
Enter word: computer
cemoprtu

To implement canonicalForm, program a loop that unloads the individual characters in the argued string and puts them in an array of char or ArrayList<Character>. ThuscanonicalForm("poor") gets an array of 4 chars ‘p', ‘o', ‘o', ‘r' or an ArrayList<Character> with the corresponding Characters. Then sort that array or ArrayList<Character>. Finally, use the sorted characters to build a new String by a loop of s = s + c, where s is a String, and c is a char or Character.

The program CanonWord needs a main method as well as the canonicalForm method. All it does is use a Scanner to get the word from the user and call canonicalWord to convert it, and print out the resulting canonical form.

2. Now write a program FindAnagrams that (in its main method) reads words.txt, and for each word there, adds it into an ArrayList<String> words and its canonical form into an ArrayList<String> codes. It obtains the canonical form by calling the same canonicalForm method you developed for CanonWord. Sort the codes ArrayList. Then hunt for duplicates in the sorted ArrayList codes. Any duplicates there will indicate anagrams in the original words. Keep track of the code with the most duplicates, and how many duplicates there are for it that you have found so far as you scan codes. Finally using this most duplicated code, scan the words list for words that have this canonical form and output them. Don't worry about ties at the longest length, just report on first anagram group with the most duplicated codes.

Test case (this is just an example, the actual words.txt you will be working with is MUCH longer):

words.txt codes sorted codes
rat art abt
hears aehrs abtt
share aehrs aehrs
tar art aehrs
bat abt aehrs
batt abtt art
shear aehrs art

The triplet of codes "aehrs" means that the corresponding words (hears, share, and shear) are anagrams. Similarly the duplicate of codes "art" indicates that rat and tar are anagrams. We are interested in the most duplicated codes, so the program should output as follows:

java FindAnagrams
hears
share
shear

We see there are two anagram groups here, one with code aehrs and the other with code art, so the most duplicated code is aehrs, corresponding to words hears, share, and shear.

For an example of comparing words next to each other in a sorted list, see line 34 of Vocabulary1.java, pg. 684, or line 30 of the program on the textbook's site.

Note that we are assuming that all the words in words.txt are in the same case, uppercase or lowercase. The textbook's words.txt is all in lowercase.

3. Write a narrative that describes how you went about designing and implementing these modifications, how you tested your program. Did you use the test case during development or did you use the final words.txt from the start, or what? Did you find it helpful that the canonicalForm computation was separately developed? Report on what you found to be the longest anagrams in the author's words.txt from the Chapter 13 area. Put your discussion in a text file called memo.txt.

Delivery:

in your it115/p4 directory:

CanonWord.java (with main and canonicalWord methods)
FindAnagrams.java (with main and the same canonicalWord method as in CanonWord)
memo.txt

in class, at the beginning of class:

Paper copies of memo.txt and p4.grade_sheet.htm, both of which should have your name on them. memo.txt should be stapled or paper-clipped together and also have the assignment name on it (p4).

Reference no: EM131316530

Questions Cloud

Create a program that allows user to enter sets of integer : Create a program that allows the user to enter sets of integer values, in any order.Per set of data,the program is to output the largest number.
Two assets-risk-free asset,and market portfolio : Suppose there are two assets, a risk-free asset, and a market portfolio. The market portfolio has an expected return of mu m = E[Rm] = 15% and a standard deviation of sigma m = 15%. The return on the risk-free asset is Rf = 5%. After thinking about t..
Determine the equilibrium position of the ball : It is assumed that the kinetic energy due to the rotation of the ball and the friction and damping forces are negligible. Determine the initial displacement to confine the ball within the well.
Research topic: safety and health program manager : I need a research for the following, The Topic: Safety and Health program manager
Write a program findanagrams that reads words txt : Now write a program FindAnagrams that (in its main method) reads words.txt, and for each word there, adds it into an ArrayList words and its canonical form into an ArrayList codes.
Calculate the npv of project : Sanders Enterprises, Inc., has been considering the purchase of a new manufacturing facility for $284,000. The facility is to be fully depreciated on a straight-line basis over seven years. It is expected to have no resale value after the seven years..
Discuss problems associated with quota sampling in surveys : How might Volvo find out why some customers prefer Mercedes or BMW?- Should marketing researchers always engage the client designing the study?
Find the natural frequencies as a function of the mass m : A plate of mass m, supported by a slender straight beam as shown in the Fig. P5.7, vibrates while sinusoidal force is applied to the center of the plate. Find the natural frequencies as a function of the mass m, flexural rigidity EI of the beam, a..
Design a project to allow a student to access current grades : Design a project to allow a student to access current grades and/or create a "What-if" situation on a continuing basis to understand where they are at any given point in the semester.

Reviews

Write a Review

Programming Languages Questions & Answers

  Correct mistakes on the command line

In this lab you will determine the shell that you are running, correct mistakes on the command line, and use filename generation. You will also learn about help that the system provides in the form of man pages, the --help option, and the bash hel..

  Design application that would output payment coupons

Design the application that would output 12 payment coupons for each of the 15 apartments in each of the 20 buildings. Each coupon should contain the building number.

  Copies the content of one file into another file

write a c program that copies the contents of one file to a destination file.

  Hubspot: inbound marketing and web 2.0

Hubspot: Inbound Marketing and Web 2.0

  Which one best describes the asymptotic class

Let f(n) = n (n + 1) / 2. Of the following possibilities, state which are true about f and of those, which one best describes the asymptotic class of f?

  Perform object-oriented analysis and design

OOAD's increasing popularity is brought about in part because of its ability to represent complex relationships, as well as data and data processing, with a consistent notation.

  Write program to compute contestant-s score

Performer's final score is determined by dropping highest and lowest score received, then averaging remaining scores. Write a program which uses this method to compute a contestant's score.

  Create a windows application and design document

create a complete C# Windows application and design documents based on the following specifications and instructions.

  Store the new generated polynomial

The program should store the new generated polynomial (to be further used in other operations),

  Describe graphical user interfaces during operation

Describe some of graphical user interfaces (GUIs) and communications messages which happen during operation of a microwave.

  Write a main program to call a procedure

Write a main program to call a procedure that converts the Fahrenheit temperature value stored in the location labeled TdegF to its Celsius equivalent. The range of temperatures is 32°F to 212°F

  Design an application for the homestead furniture store

Design an application for the Homestead Furniture Store that gets sales transaction data, including an account number, customer name, and purchase price.

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