Question
In JAVA Code given: package edu.wit.cs.comp1050; public class LA1a { /** * Returns an array with counts for each * letter from a-z (case-insensitive), *
In JAVA
Code given:
package edu.wit.cs.comp1050;
public class LA1a { /** * Returns an array with counts for each * letter from a-z (case-insensitive), * ignoring all other characters: * * [0]: number of a/A's * [1]: number of b/B's * ... * [25]: number of z/Z's * * @param word input word * @return count of case-insensitive letters */ public static int[] countLetters(String word) { int[] counts = new int[26]; // write your code here return counts; } /** * Compares two arrays and * returns true if they have * the same contents * * @param c1 array 1 * @param c2 array 2 * @return true if c1 and c2 have the same contents */ public static boolean sameCounts(int[] c1, int[] c2) { return false; // write your code here }
/** * Inputs two phrases and outputs * if they are anagrams (ignoring * case and any non-letter * characters) * * @param args command-line arguments, ignored */ public static void main(String[] args) { // write your code here }
}
Problem a (LA1a.java) An anagram is direct word switch or word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once; for example, you can rearrange the letters of the word cinema to produce iceman. Your task is to write a simple anagram detector: it compares two phrases and reports whether.or not they use the same number of the same letters (ignoring case and any non-letter symbols). The detector will work by checking if both phrases use the same number of each letter: The countLetters method counts how many times each letter occurs in a word and returns an array of integers representing this tally. The oth element represents how many a or A's were found in the word, the 1st element represents how many b/B's, and the 25th element how many z/Z's All other symbols are ignored in the resulting array. The sameCounts method compares two integer arrays and returns true only if they have the same contents, including their sizes and values for each element. Note: you are not allowed to use Arrays, equals, or equivalent, to implement this method. 1. 2. Your main method should prompt the user for two phrases, then report whether or not they are anagrams; for example... Enter phrase 1: cinema Enter phrase 2: iceman These phrases are anagrams. Enter phrase 1: cinema Enter phrase 2: snowman These phrases are not anagrams. Enter phrase 1: Anagrams! Enter phrase 2:Ars Magna These phrases are anagramsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started