Advertisement
Guest User

Untitled

a guest
Oct 19th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. Two words or phrases in English are anagrams if their letters (and only their letters), rearranged, are the same. We assume that upper and lower case are indistinguishable, and punctuation and spaces don't count. Some examples and non-examples:
  2.  
  3. * The eyes / they see (yes)
  4. * moo / mo (no)
  5. * Clint Eastwood / Old west Action! (yes)
  6. * Dormitory / Dirty Room (yes)
  7.  
  8. For more examples, see here.
  9.  
  10. Your job for this assignment is to solve a slight variant of the traditional anagram problem called superanagram. Here you are to write a two class application that reads in two words or phrases from the keyboard, and then judges if the first phrase is an anagram of some of the letters in the second phrase. Here are some examples:
  11.  
  12. * mo / moo (yes)
  13. * mo / mOO (yes - capitalization doesn't matter)
  14. * moo / mo (no - first phrase is NOT an anagram of some (or all) of letters of second)
  15. * rip / ziPPer (yes)
  16. * abc / aabc (yes)
  17. * aabc / abcde (no - too few a's in the second string)
  18. * flipper / rip (no)
  19. * Clint Eastwood / Old west Action! (yes - the two can have exactly the same letters)
  20.  
  21. You must use the Scanner class to read in the input strings. Use the nextLine() Scanner method, rather than next(), since spaces may be present in the two phrases that are submitted.
  22.  
  23. Your program should either print YES, if the superanagram relationship is satisfied, or NO, if it isn't.
  24.  
  25. The classes MUST be called SuperAnTester, and SuperAnagram
  26.  
  27. Some tips:
  28.  
  29. * use the String methods toLowerCase() and (possibly) toCharArray(). The former takes all letters in a String and changes them to lower case; the latter converts a String into an array of characters. Also, this assignment is - of course - about characters and character matching. For some useful background on characters and how to work with them, watch the movies in the textbook at the ends of section 4.1 and 7.1.
  30.  
  31. * Very important: suppose you have two arrays of characters such that the first is purported to be an embedded anagram of the second, in the sense we've described above. How can you tell? The single most important thing to do, before you write a single line of code, is to work out a paper and pencil algorithm that distinguishes between superanagrams and non-superanagrams.
  32.  
  33. * Your classes must be commented! In particular, each method must have a one line comment just below the header line, which tells what the method is supposed to do.
  34.  
  35. * Algorithm Idea #1: make a scoreboard for the letters a to z. Every time you encounter a letter in the second String, up its count by 1; Then, every time you encounter a letter in the first String, lower its count by 1. Accept if the scoreboard ends up with all entries >= 0. (of course make sure you understand why this is - use pencil and paper to convince yourself!!).
  36.  
  37. * Algorithm Idea #2: convert strings to arrays. March down first array (representing the first string). When you encounter a letter, look for it in the second array. If you find it, blank out the occurrence in the second array; if you don't find it - it's not a super anagram. When you're all done, you've got a superanagram if your search in the second array never goes bad.
  38.  
  39. IMPORTANT NOTE: Do NOT put import statements in your classes. They are already included in the evaluation code on our end. Read in the two strings you are testing in the SuperAnTester class.
  40.  
  41. Place your SuperAnTester class in the box below.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement