Two words, word1 and word2, are similar if and only if all the characters in word1...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Two words, word1 and word2, are similar if and only if all the characters in word1 are in word2; and all the characters in word2 are in word1; including the same number of duplication. For example, abba and baba are similar; but aaba and baba are not similar. Obviously if the two words are of different lengths, they are not similar. We use the following algorithm to check two words which are similar: For each word, we associate a marker to each of the characters. For example, if the word is abba, we add a marker to each character; for example, an hyphen; now the word abba becoming a-b-b-a-. To check two words which are similar, we get a character from word1, if that character is in word2, we "mark" the character; for example, change hyphen (-) to another special symbol for the two words; for example, an asterisk (*). If all the characters are marked in the two words, then the two words are similar. We propose the following UML diagram to describe a word or two words: CharInfo -char ch -char marker +Charlnfo(char ch, char marker) 1..1 +Charinfo(Charinfo ci) +char getChar( +char getMarker() +void setinfo(char ch, char marker) +void displayInfo() In the above UML diagram: 1..1 TwoWords -Charlnfo] word1 -Charlnfo word2 +TwoWords (Charlnfo@ word1, Charinfo] word2) -boolean charinWord(char ch, Charinfo word) + boolean areSimilar The class Charlnfo has two instance variables, a character ch and a character marker The class TwoWords has two instance variables, word1 and word1 which are two arrays of Charlnfo. This class has a constructor, a method to check if a character is inside a word and a method to check if the two words are similar. During the processing, you "mark" the characters. Let us talk about the main class: -static Charlnfoll getCIArray(String word) -static void displayInfo(Charlnfol ciArray) + static void main(String args) You construct a data file called e3.txt consists of the following information: (you can copy and paste them) In the main method aaabbb ababab bababa abc I will use the above sample data file to test your design. E_3 bbbaaa bababb ababab abcdef - You read the two words - Convert each word to an array of Charlnfo - Construct an object of the class TwoWords and check if the two words are the similar - The displayInfo method displays the array of Charinfo. Upon execution of your program, you see the following analysis and result: Given the following words. info a-a-a-b-b-b- b-b-b-a-a-a- Analysis Given a*a*a*b*b*b* b*b*b*a*a*a* ==> Similar the following words' info a-b-a-b-a-b- b-a-b-a-b-b- Analysis a*b*a*b*a-b- b*a*b*a*b-b- ==>Not Similar Analysis Given the following words info Given the following words info a-b-c- b-a-b-a-b-a- a-b-a-b-a-b- a-b-c-d-e-f- b*a*b*a*b*a* a*b*a*b*a*b* ==> Similar Analysis a-b-c- a-b-c-d-e-f- ==>Not Similar Save all the classes (remove the public from all classes so that I can compile) in a Java file called YourName_E_3.java and upload this Java file. Two words, word1 and word2, are similar if and only if all the characters in word1 are in word2; and all the characters in word2 are in word1; including the same number of duplication. For example, abba and baba are similar; but aaba and baba are not similar. Obviously if the two words are of different lengths, they are not similar. We use the following algorithm to check two words which are similar: For each word, we associate a marker to each of the characters. For example, if the word is abba, we add a marker to each character; for example, an hyphen; now the word abba becoming a-b-b-a-. To check two words which are similar, we get a character from word1, if that character is in word2, we "mark" the character; for example, change hyphen (-) to another special symbol for the two words; for example, an asterisk (*). If all the characters are marked in the two words, then the two words are similar. We propose the following UML diagram to describe a word or two words: CharInfo -char ch -char marker +Charlnfo(char ch, char marker) 1..1 +Charinfo(Charinfo ci) +char getChar( +char getMarker() +void setinfo(char ch, char marker) +void displayInfo() In the above UML diagram: 1..1 TwoWords -Charlnfo] word1 -Charlnfo word2 +TwoWords (Charlnfo@ word1, Charinfo] word2) -boolean charinWord(char ch, Charinfo word) + boolean areSimilar The class Charlnfo has two instance variables, a character ch and a character marker The class TwoWords has two instance variables, word1 and word1 which are two arrays of Charlnfo. This class has a constructor, a method to check if a character is inside a word and a method to check if the two words are similar. During the processing, you "mark" the characters. Let us talk about the main class: -static Charlnfoll getCIArray(String word) -static void displayInfo(Charlnfol ciArray) + static void main(String args) You construct a data file called e3.txt consists of the following information: (you can copy and paste them) In the main method aaabbb ababab bababa abc I will use the above sample data file to test your design. E_3 bbbaaa bababb ababab abcdef - You read the two words - Convert each word to an array of Charlnfo - Construct an object of the class TwoWords and check if the two words are the similar - The displayInfo method displays the array of Charinfo. Upon execution of your program, you see the following analysis and result: Given the following words. info a-a-a-b-b-b- b-b-b-a-a-a- Analysis Given a*a*a*b*b*b* b*b*b*a*a*a* ==> Similar the following words' info a-b-a-b-a-b- b-a-b-a-b-b- Analysis a*b*a*b*a-b- b*a*b*a*b-b- ==>Not Similar Analysis Given the following words info Given the following words info a-b-c- b-a-b-a-b-a- a-b-a-b-a-b- a-b-c-d-e-f- b*a*b*a*b*a* a*b*a*b*a*b* ==> Similar Analysis a-b-c- a-b-c-d-e-f- ==>Not Similar Save all the classes (remove the public from all classes so that I can compile) in a Java file called YourName_E_3.java and upload this Java file.
Expert Answer:
Answer rating: 100% (QA)
import javaioFile import javaioFileNotFoundException ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Canton Company makes two types of cell phones. Handy is a thin, pocket-size cell phone that is easy to carry around. Action is a palm-size phone convenient to hold while the user is talking. During...
-
MileHi Mountain Bikes Ltd. markets mountain-bike tours to clients vacationing in various locations in the mountains of British Columbia. On March 1, 2012, the company had a balance of $15,000 in...
-
In Exercises 1128, evaluate the iterated integral. (/2 cos x (1 + sin x) dy dx
-
What are the different types of schemes associated with complex frauds?
-
Interest during Construction Grieg Landscaping began construction of a new plant on December 1, 2010. On this date the company purchased a parcel of land for $139,000 in cash. In addition, it paid...
-
Use conversion algorithm to convert ER diagram to Relational Model Or All ER to relational model intermediatory conversion steps with final relational model (i.e. step 4) RUberID REmail Passwd...
-
Investors need financial information about a company's a) research and development plans for a potential product line. b) debt payments scheduled for the upcoming year. c) amount of net income...
-
How do religious institutions operate as socialization agents, transmitting moral values, belief systems, and rituals that contribute to individual and collective identity formation?
-
Dan Schmidt plans to invest in a rental property worth $240,000. He plans to hold the property for 4 years and expects to sell it for $280,000 at the end of the fourth year. He estimates that the...
-
3- How does the Accounts Payable controlling account in the general ledger relate to the accounts payable subsidiary ledger? 4- Why should a business closely monitor its accounts payable?
-
If your client approaches you for an opinion, can you cite a Private Letter Ruling as primary authority in their tax memorandum response? Why or why not?
-
List the variables underlying Black-Scholes option pricing model and point out how they affect option prices.
-
During the summer months ( December to February. Inclusive), an average of five marriages per month take place in a small city. Assuming that these marriages occur randomly and independently of one...
-
Describe a group you belong or have belonged discuss the stages of group development and suggest how to improve the group effectiveness by using the group development model.
-
Create an abstract Student class for Parker University. The class contains fields for student ID number, last name, and annual tuition. Include a constructor that requires parameters for the ID...
-
Which of the following statements is true about all JavaFX applications? a. All JavaFX must use CSS for styling. b. All JavaFX applications must call the launch() method. c. Every JavaFX calls the...
-
Which of the following expressions correctly returns an integer that represents the month of a LocalDate object named hireDate? a. getMonth(hireDate) b. getMonthValue(hireDate) c....
-
Assuming that the latent heat of sublimation of ice \(L_{\mathrm{S}}=2500 \mathrm{~kJ} / \mathrm{kg}\) is independent of temperature and the specific volume of the solid phase is negligible compared...
-
Calculate the slope of the solid-liquid transition line for water near the triple point \(T=273.16 \mathrm{~K}\), given that the latent heat of melting is \(80 \mathrm{cal} / \mathrm{g}\), the...
-
Study the state of equilibrium between a gaseous phase and an adsorbed phase in a singlecomponent system. Show that the pressure in the gaseous phase is given by the Langmuir equation \[...
Study smarter with the SolutionInn App