Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 of regular anagrams: * The eyes / they see (yes) * moo / mo (no) * Clint Eastwood / Old west Action! (yes) * Dormitory / Dirty Room (yes) 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 outputs true if the first phrase is an anagram of some of the letters in the second phrase, false if it is not. Here are some examples: * mo / moo (true) * mo / mOO (true - capitalization doesn't matter) * moo / mo (false - first phrase is NOT an anagram of some (or all) of letters of second) * rip / ziPPer (true) * abc / aabc (true) * aabc / abcde (false - too few a's in the second string) * flipper / rip (false) * Clint Eastwood / Old west Action! (true - the two can have exactly the same letters) * a stitch in time saves nine / is this meant as an incentive? (true) * narcissism / one man crisis (false- can you see why?) Example of a program run:

Enter a phrase: > Clint Eastwood Enter another phrase: >Old west Action! true 

TEST CASES: This file contains test cases to run your code on when you have it working. Most of the code has been written- you can finish implementing it and use it to fully test your SuperAnagram code. NOTE: do not submit this class to OWL. This is for your testing purposes only. If your code passes all of these tests your code is likely to get max points. SuperAnagram Test Cases PROJECT REQUIREMENTS:

Your classes must be called SuperAnTester, and SuperAnagram.

Your SuperAnTester class must prompt the user to enter each phrase. It must use a Scanner object to read in the input phrases.

Your program must either print true, if the superanagram relationship is satisfied, or false if it isn't. All console Input and Output must be done by the SuperAnTester class.

Your SuperAnagram class must have an isSuperAnagram method that returns boolean and takes two String parameters- the phrases to be tested. Your isSuperAnagram method must return true if the superanagram relationship is satisfied, false, if it isn't.

Your SuperAnTester class must create an instance of the SuperAnagram class and call its isSuperAnagram method to determine if the input satisfies the superanagram relationship.

Your SuperAnagram class must use the default constructor (no parameters) only.

You may NOT import and use the ArrayList class for this project. Major point deduction for this. Note that you do want to use one or more arrays in this project.

Some tips:

Remember to use the nextLine method, rather than next, since spaces may be present in the two phrases that are submitted.

Use the String methods toLowerCase and, possibly, toCharArray. (Consult the Java API).

Punctuation and any characters other than letters a-z are ignored.

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.

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.

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!!).

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.

Run all of the test cases provided on your solution. You can write code to use the arrays to test your SuperAnagram class. Follow the pseudocode provided. Note that this is an optional suggestion.

IMPORTANT NOTE: Do NOT put import statements in your classes. They are already included in the evaluation code on our end. Place your SuperAnTester class in the box below. import java.util.Scanner;

Place your SuperAnagram class here.

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

Recommended Textbook for

More Books

Students also viewed these Databases questions