Wednesday, March 21, 2012

Lab 18: Pride and Prejudice

In this lab we will explore how the characters in Jane Austen's masterpiece "Pride and Prejudice" feel. For this, you first need to head on over to Project Gutenberg and download a copy of the plain text version of the book to your desktop. Then, drag it over to your eclipse project (within the project, not within the src folder).

You will now write a program that reads this file looking for the phrase "I am" and prints out each time it finds it followed by the next four words, also keeping a count of how many it has found. The output of your program will look something like:
1- I am thinking of his marrying
2- I am sure she is not
3- I am glad to find that
4- I am not acquainted with him
5- I am sick of Mr. Bingley,"
6- I am sorry to hear _that_;
7- I am ! and it is
8- I am not afraid; for though
9- I am particularly acquainted with my

...and so on...

280- I am afraid; for what becomes
281- I am not indebted for my
282- I am more likely to want
283- I am happier even than Jane;
284- I am sure Wickham would like

You will find Scanner.findWithinHorizon("I am",0) will come in handy for this.

Your program will also write to a file called "out.txt" the count of how many times it has found "I am sure", "I am afraid" and "I am not afraid". The file should have these contents:
I am sure: 36
I am afraid:15
I am not afraid:5

2 comments:

John Clark said...

There are actually 57 instances of "I am sure" and 6 instances of "I am not afraid"

Jose Vidal said...

OK, it's probably a "sure" vs "sure." or similar issue. The specific number is not important for this lab.

Thanks!