JAVA PROGRAMMING Two words (spelt in uppercase) are similar if and only if all letters in the 1st word are in the 2nd word and all letters in the 2nd word are in the 1st word; including the same number of duplications. For example, ABBA and BABA are similar; however, BABA and BAAA are not similar. To check two words which are similar, we can use two integer arrays, each has 26 elements (as we have 26 letters), you can assume that 1st array element stores the number of letter ‘A’, 2nd array element stores the number of letter ‘B’, and so on. What you need to do now is to check whether the two integer arrays are equal to decide whether the two words are similar. We propose following UML for this question: The class TwoWords has two String instance variables. In this class, other than the constructors, accessor and mutator methods; we have two important methods: the countInfo method receives a String parameter (a word, for example) counts and stores the letters’ info in an integer array and returns this array; the areSimilar method is to check whether the two words are similar. - Main method drives the following interaction:
JAVA PROGRAMMING
Two words (spelt in uppercase) are similar if and only if all letters in the 1st word are in the 2nd word and all letters in the 2nd word are in the 1st word; including the same number of duplications. For example, ABBA and BABA are similar; however, BABA and BAAA are not similar.
To check two words which are similar, we can use two integer arrays, each has 26 elements (as we have 26 letters), you can assume that 1st array element stores the number of letter ‘A’, 2nd array element stores the number of letter ‘B’, and so on. What you need to do now is to check whether the two integer arrays are equal to decide whether the two words are similar.
We propose following UML for this question:
The class TwoWords has two String instance variables. In this class, other than the constructors, accessor and mutator methods; we have two important methods: the countInfo method receives a String parameter (a word, for example) counts and stores the letters’ info in an integer array and returns this array; the areSimilar method is to check whether the two words are similar.
- Main method drives the following interaction:
![TwoWords
1-String word1
1-String word2
Exam_Q4
+ TwoWords0
-static Scanner input
+TwoWords(String word1, String word2)
+TwoWords(TwoWords tw)
+ String getWord10
static void main(String args)
String getWord20
+void setinfo(String word1, String word2)
-int] countinfo(String word)
+boolean areSimilar)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fdd8f2877-2578-48c0-ab77-5dda294aaf93%2F8bfe5408-e6f6-48f2-b224-469edf36a0c7%2Foxdm1k_processed.png&w=3840&q=75)


Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images









