Question

Consider the two strings "doggie dish" and "Drip coffee". What letters do they have in common?...

Consider the two strings "doggie dish" and "Drip coffee". What letters do they have in common? That is, what is the letter intersection count for the pair of strings?

Let's look at 'd' first. The first string has 2 d's (d's occurrence count is 2), while the second has just 1 d (capitalization doesn't count) - so the intersection for the strings for d is 1. What about g? There the occurrence counts are 2 and 0, so the intersection is 0. The counts for the letter e is 1 and 2, so the intersection is just 1. In other words, the intersection for a particular letter is calculated by 1) determining the occurrence count for the letter in the first string; determining the occurrence count for the letter in the second string; and then reporting the minimum of the two counts.

For this assignment your job is to create a class that takes two strings as input (passed as parameters to the class constructor) and reports the letter intersection count in the strings for each letter. Letter case does not matter: both 'E' and 'e' count for 'e'.

Let's look at a more complete example. Suppose the strings are

"The Erie canal runs east/west in upstate NY!"
and
"The time has come, the walrus said, to speak of many things;"

For these strings the full intersection is below - and this display should be what your output looks like for this project.

Common Letter Count
a 4
b 0
c 1
d 0
e 5
f 0
g 0
h 1
i 2
j 0
k 0
l 1
m 0
n 2
o 0
p 1
q 0
r 1
s 4
t 5
u 1
v 0
w 1
x 0
y 1
z 0


That is, the entry for 'm' is 0: there are 0 m's in the first string, and 3 in the second string. Similarly, the entry for 'u' is 1: there are 2 u's in the first string, just 1 in the second string. To repeat, the value your code should produce for a letter should be the minimum of its occurrence count in the first string and its occurrence count in the second string.

Here is the driver class for this application:

import java.util.Scanner;
public class IntersectTester{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    System.out.println("Enter first string");
    String s = scan.nextLine();
    System.out.println("Enter second string");
    String t = scan.nextLine();
    LetterIntersect i = new LetterIntersect(s,t);
    i.processStrings();
  } 
}   


Your job for this assignment, then, is to create a LetterIntersect class that, working with the given driver, will properly produce the indicated table. The class constructor should have two parameters - the strings to be studied. The class must also include a processStrings() method with no arguments, which processes the strings and then prints out the table of common occurrences.

Your solution must make use of one or several arrays in an essential way. Also, your LetterIntersect class should divide up the chores of the assignment systematically, and this decomposition should be reflected in the various methods that support the top-level method processStrings(). My code, for example, uses two array instance variables and has a constructor, a processStrings() method, and two additional major methods.

Helpful: watch the movie at the end of Section 7.1, which explains how to work with arrays that have indices that are naturally non-numeric (as is the case here - arrays in this project are naturally indexed a-z).

Paste your LetterIntersect code in the box below. Include no import statements (none are needed).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Output:

Doggie Dish Enter second string Drip Coffee Alphabet Count

Answer Here is the complete code import java.io. *; import iava.util. Scanner import ava util.*; //class LetterInterSect claschar ch1=a int small-0 //print the intersection of two strings System.out.println(Alphabet tCount System.out.println( forcntl0; //counting the occurence for (int k 0; k<lenl; k++) ch1=str. charAt (k) ; if(ch1==1) cntl++ array add (cntl); return a//driver class public class IntersectTester public static void main (String[] args) Scanner scan-new Scanner (System. in); Sy

Add a comment
Know the answer?
Add Answer to:
Consider the two strings "doggie dish" and "Drip coffee". What letters do they have in common?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Code: Complete the program that reads from a text file and counts the occurrence of...

    JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...

  • Two words or phrases in English are anagrams if their letters (and only their letters), rearranged,...

    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. Two phrases are anagrams if they contain exactly the same number of exactly the same letters, e.g., 3 A's, 0 B's, 2 C's, and so forth. Some examples and non-examples of regular anagrams: * The eyes / they see (yes) * moo / mo (no) *...

  • Trying to practice this assignment Argument list: the *yahoonews.txt Data file: yahoonews.txt Wr...

    Trying to practice this assignment Argument list: the *yahoonews.txt Data file: yahoonews.txt Write a program named WordCount.java, in this program, implement two static methods as specified below: public static int countWord(Sting word, String str) this method counts the number of occurrence of the word in the String (str) public static int countWord(String word, File file) This method counts the number of occurrence of the word in the file. Ignore case in the word. Possible punctuation and symbals in the file...

  • Help check why the exception exist do some change but be sure to use the printwriter...

    Help check why the exception exist do some change but be sure to use the printwriter and scanner and make the code more readability Input.txt format like this: Joe sam, thd, 9, 4, 20 import java.io.File; import java.io.PrintWriter; import java.io.IOException; import java.io.FileNotFoundException; import java.io.FileWriter; import java.util.Scanner; public class Main1 { private static final Scanner scan = new Scanner(System.in); private static String[] player = new String[622]; private static String DATA = " "; private static int COUNTS = 0; public static...

  • Write a Java class named StringProcess that prompts the user to enter two non-empty strings and...

    Write a Java class named StringProcess that prompts the user to enter two non-empty strings and report the followings: 1) The length of the two strings 2) The ASCII value of the first letter in the first string 3) The ASCII value of the last letter in the second string 4) Whether the second string is a substring of the first string. Outputs: Your output should look similar as follows. Please enter the first string: Carrot Please enter the second...

  • DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an...

    DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an unknown number of cells filled with data. As before, the array will already be filled with strings, some of which contain the string "Angela". You will create a method called countItUp which returns and integer array containing the number of times each of the letters in my name occur within the strings within this array. For example, if the input array was wordFun =...

  • DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an...

    DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an unknown number of cells filled with data. As before, the array will already be filled with strings, some of which contain the string "Angela". You will create a method called countItUp which returns and integer array containing the number of times each of the letters in my name occur within the strings within this array. For example, if the input array was wordFun =...

  • Here is my code to put a quote down, flip it, and reverse it. I do...

    Here is my code to put a quote down, flip it, and reverse it. I do not have much knowledge on coding. Does my code only use Variables, Console I/O, Java Program Design, Intro to IDEs, If Statements, Selection and Conditional Logic, Strings, Loops, Nesting, and Iteration? If not, could it be fixed to only use them? These are the offical steps of the assignment: - Ask a user to enter a quote - whether it's several sentences or a...

  • The following code uses a Scanner object to read a text file called dogYears.txt. Notice that...

    The following code uses a Scanner object to read a text file called dogYears.txt. Notice that each line of this file contains a dog's name followed by an age. The program then outputs this data to the console. The output looks like this: Tippy 2 Rex 7 Desdemona 5 1. Your task is to use the Scanner methods that will initialize the variables name1, name2, name3, age1, age2, age3 so that the execution of the three println statements below will...

  • You will write a class called Shoe.java Shoe.java should have Three instance variables String brand (cannot...

    You will write a class called Shoe.java Shoe.java should have Three instance variables String brand (cannot be blank) double size (from 5 to 12) int color (a number from 1 to 5 representing one of 5 colors) This code is to control the amount of colors. the colors represented are as follows 1. red 2. green 3. blue 4. black 5. grey One constructor, one get method per instance variable, one set method per instance variable. You will need a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT