Question: My Lab4 code: import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; public class Seuss { public static void main(String args[]) throws FileNotFoundException { LinkedSet set=new

 My Lab4 code: import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner;

My Lab4 code:

import java.io.File;

import java.io.FileNotFoundException;

import java.io.PrintWriter;

import java.util.Scanner;

public class Seuss {

public static void main(String args[]) throws FileNotFoundException

{

LinkedSet set=new LinkedSet();

File infile = new File("./src./greenEggs.txt");

File outfile = new File("words.txt");

String word=null;

PrintWriter out=null;

Scanner read = null;

try {

read = new Scanner(infile);

out=new PrintWriter(outfile);

while(read.hasNext())

{

word=remmovePunc(read.next());

set.add(word);

}

System.out.print(set);

while(true)

{

word=set.remove();

if(word==null)

{

break;

}

out.write(word+" ");

out.flush();

}

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public static String remmovePunc(String s)

{

String str="";

String a=s.toLowerCase();

for(int i=0;i

{

if (Character.isLetter(a.charAt(i))){

str=str+a.charAt(i);

}

}

return str;

}

} The text file greenEggs.txt:

I am Sam I am Sam Sam I am That Sam I am! That Sam I am! I do not like that Sam I am! Do you like green eggs and ham? I do not like them, Sam I am. I do not like green eggs and ham. Would you like them here or there? I would not like them here or there. I would not like them anywhere. I do not like green eggs and ham. I do not like them, Sam I am. Would you like them in a house? Would you like them with a mouse? I do not like them in a house. I do not like them with a mouse. I do not like them here or there. I do not like them anywhere. I do not like green eggs and ham. I do not like them, Sam I am. Would you eat them in a box? Would you eat them with a fox? Not in a box. Not with a fox. Not in a house. Not with a mouse. I would not eat them here or there. I would not eat them anywhere. I would not eat green eggs and ham. I do not like them, Sam I am. Would you? Could you? In a car? Eat them! Eat them! Here they are. I would not, could not, in a car. You may like them. You will see. You may like them in a tree! I would not, could not in a tree. Not in a car! You let me be! I do not like them in a box. I do not like them with a fox. I do not like them in a house. I do not like them with a mouse. I do not like them here or there. I do not like them anywhere. I do not like green eggs and ham. I do not like them, Sam I am. A train! A train! A train! A train! Could you, would you, on a train? Not on a train! Not in a tree! Not in a car! Sam! Let me be! I would not, could not, in a box. I could not, would not, with a fox. I will not eat them with a mouse. I will not eat them in a house. i will not eat them here or there. I will not eat them anywhere. I do not eat green eggs and ham. I do not like them, Sam I am. Say! In the dark? Here in the dark! Would you, could you, in the dark? I would not, could not, in the dark. Would you, could you, in the rain? I would not, could not, in the rain. Not in the dark. Not on a train. Not in a car. Not in a tree. I do not like them, Sam, you see. Not in a house. Not in a box. Not with a mouse. Not with a fox. I will not eat them here or there. I do not like them anywhere! You do not like green eggs and ham? I do not like them, Sam I am. Could you, would you with a goat? I would not, could not, with a goat! Would you, could you, on a boat? I could not, would not, on a boat. I will not, will not, with a goat. I will not eat them in the rain. I will not eat them on a train. Not in the dark! Not in a tree! Not in a car! You let me be! I do not like them in a box. I do not like them with a fox. I will not eat them in a house. I do not like them with a mouse. I do not like them here or there. I do not like them ANYWHERE I do not like green eggs and ham! I do not like them, Sam I am. You do not like them. So you say. Try them! Try them! And you may. Try them and you may, I say. Sam! If you will let me be, I will try them. You will see. Say! I like green eggs and ham! I do! I like them, Sam I am! And I would eat them in a boat. And I would eat them with a goat... And I will eat them in the rain. And in the dark. And on a train. And in a car. And in a tree. They are so good, so good, you see! So I will eat them in a box. And I will eat them with a fox. And I will eat them in a house. And I will eat them with a mouse. And I will eat them here and there. Say! I will eat them ANYWHERE! I do so like green eggs and ham! Thank you! Thank you, Sam I am! 
Next, write a program Seuss2.java that uses a map to get the number of occurrences of each word in the book Green Eggs and Ham. The program should work similarly to the program Seuss.java that you wrote for Lab 4 (i.e., ignore punctuation and capitalization [thank-2, good-2, i-1, try-4, so:5, boat-3, goat-4, rain-4, dark=7, the:11, say:5. on=7, train-9, be-4, me=4, let-4, tree-6, see-4, will-21, may-4, are-2, they-2, car=7, could=14, fox=7, box-7, eat-25, mouse-8, with:19, house-8, a=59, in-40, anywhere-8, there-9, or-8, here-11, would-26, them-61, ham-11, and-25, eggs-11, green=11, you-34, like-44, not-84, do-37, that-3, sam=19, am=16, i-85]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!