Class Anagram


  • public class Anagram
    extends java.lang.Object
    A class that tests whether two strings are anagrams.

    The provided code is incomplete. Modify it so that it works properly and passes the tests in AnagramTest.java.

    See Also:
    MP2 Documentation, Definition of anagram
    • Constructor Summary

      Constructors 
      Constructor Description
      Anagram()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean areStrictAnagrams(java.lang.String first, java.lang.String second)
      Given two strings return true if they are anagrams of each other.
      static void main(java.lang.String[] unused)
      Solicits two strings from the user and print if they are anagrams.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Anagram

        public Anagram()
    • Method Detail

      • areStrictAnagrams

        public static boolean areStrictAnagrams(java.lang.String first,
                                                java.lang.String second)
        Given two strings return true if they are anagrams of each other.

        Two strings are anagrams if they contain the same letters but in a different order. You should ignore punctuation and whitespace, so only consider the letters A-Z, a-z, and the numbers 0-9. You should also require that the anagram use the same letters the same number of times. (Some anagram definitions are more flexible.)

        • Example: "a decimal point" anagrams to "i’m a dot in place" but not to "I'm a dot in place."
        • Example: "rail safety" anagrams to "fairy tales".

        Either the first or second string may be null, in which case you should return false. Empty strings require no special treatment.

        Parameters:
        first - the first string to use for the anagram comparison
        second - the second string to use for the anagram comparison
        Returns:
        true if the two strings are anagrams ignoring punctuation
        See Also:
        Definition of anagram
      • main

        public static void main(java.lang.String[] unused)
        Solicits two strings from the user and print if they are anagrams.

        You are free to review this function, but should not modify it. Note that this function is not tested by the test suite, as it is purely to aid your own interactive testing.

        Parameters:
        unused - unused input arguments