Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this lab assignment, you will create a Java application that uses a stack to return a list containing all permutations of a given string.

In this lab assignment, you will create a Java application that uses a stack to return a list containing all permutations of a given string. For example, there are six permutations of the letters in the string tra. tra, rta, rat, tar, atr, art In general, a string with n distinct letters has n! ("n factorial") permutations. For instance, a 4-letter string has 4! = 24 permutations, a 5-letter string has 5! = 120 permutations, a 6-letter string has 6! = 720 permutations, and so on. To help you get started: Suppose you want to find all permutations of the string tra. Push the string +tra onto a stack While the stack is not empty Pop off the top of the stack. if that string ends in a + (such as tra+) Remove the + and add the string to the list of permutations else for each letter to the right of the + Remove the letter from the right of the + Insert it just before the + Push the resulting string onto the stack. For example, if you pop a+cre, then you will push ac+re, ar+ce, ae+cr. Note: When the string you are using contains duplicate letters, a simple permutations generator will yield some duplicate permutations. For instance, the permutations of "dda" will generate the 3! = 6 permutations: dda, dda, dad, dad, add, add Next, your program will determine which of the permutations is an English word by looking them up in a dictionary. Filtering out the English words yields: dad, dad, add, add In such cases, your program should also filter out duplicates to yield the final list: dad, add Requirements: Your implementation should include a PermutationsConsole class and a PermutationsCalculator class. PermutationsCalculator class: 1. create a field which is an unbounded stack; use the stack implementation from chapter 2 in the text 2. create a method with a String parameter which will calculate all the permutations of the parameter; store the permutations in a list and return the list PermuationsConsole class: 1. create an output file named "perms.dat" 2. read the given English dictionary text file and create a list of English words; use the ArrayList class 3. use a loop to read words until the user wants to stop 4. for each word: a. send it to the PermutationsCalculator class for processing b. a list of permutations is returned from the PermutationsCalculator class c. print the original word and the list of permutations to the output file d. create another list to hold the permutations which are English words e. for each word in the list of permutations check to see if it is an English word and if so, add it to the list of English words; this list should not contain duplicates, so do not add a word to the list if it's already in the list f. print out the list of English words to the output file; if there are no English words then state that condition Do not put all the code in the main method. Use other methods to do some of the work. Clearly label all the output written to the output file. Include the original string expression, its permutation list, and the list of English words contained in the permutation list if any.

use stacks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+4. What impediments deal with regulators?

Answered: 1 week ago

Question

6. Identify seven types of hidden histories.

Answered: 1 week ago

Question

What is human nature?

Answered: 1 week ago