Using multipleLists, Multi-Lists (A list inside a list), Using multiple interacting classes, ClassArrayList, Class LinkedList, implementing classes, string manipulations,reading files.
i will attach the files and description
the details in “Programming doc”
and use the classes:
mary
alone
Raven
and also the MyLinkedListInterface
Alone by Edgar Allen Poe
From childhoods hour I have not been
As others were; I have not seen
As others saw; I could not bring
My passions from a common spring.
From the same source I have not taken
My sorrow; I could not awaken
My heart to joy at the same tone;
And all I loved, I loved alone.
Then in my childhood, in the dawn
Of a most stormy life was drawn
From every depth of good and ill
The mystery which binds me still:
From the torrent, or the fountain,
From the red cliff of the mountain,
From the sun that round me rolled
In its autumn tint of gold,
From the lightning in the sky
As it passed me flying by,
From the thunder and the storm,
And the cloud that took the form
When the rest of Heaven was blue
Of a demon in my view.
“Mary had a little lamb,”
BY SARAH JOSEPHA HALE
Mary had a little lamb,
Its fleece was white as snow;
And everywhere that Mary went
The lamb was sure to go.
It followed her to school one day,
Which was against the rule;
It made the children laugh and play
To see a lamb at school.
And so the teacher turned it out,
But still it lingered near,
And waited patiently about
Till Mary did appear.
Why does the lamb love Mary so?
The eager children cry;
Why, Mary loves the lamb, you know,
The teacher did reply.
The Raven
By Edgar Allan Poe
Once upon a midnight dreary, while I pondered, weak and weary,
Over many a quaint and curious volume of forgotten lore,
While I nodded, nearly napping, suddenly there came a tapping,
As of someone gently rapping, rapping at my chamber door.
“Tis some visitor,” I muttered, “tapping at my chamber door
Only this, and nothing more.”
Ah, distinctly I remember it was in the bleak December,
And each separate dying ember wrought its ghost upon the floor.
Eagerly I wished the morrow; vainly I had sought to borrow
From my books surcease of sorrow, sorrow for the lost Lenore
For the rare and radiant maiden whom the angels name Lenore
Nameless here for evermore.
And the silken, sad, uncertain rustling of each purple curtain
Thrilled me, filled me with fantastic terrors never felt before;
So that now, to still the beating of my heart, I stood repeating,
“Tis some visitor entreating entrance at my chamber door;
Some late visitor entreating entrance at my chamber door;
This it is, and nothing more.”
Presently my soul grew stronger; hesitating then no longer,
“Sir,” said I, “or Madam, truly your forgiveness I implore;
But the fact is I was napping, and so gently you came rapping,
And so faintly you came tapping, tapping at my chamber door,
That I scarce was sure I heard you” here I opened wide the door;
Darkness there, and nothing more.
Deep into that darkness peering, long I stood there wondering, fearing,
Doubting, dreaming dreams no mortal ever dared to dream before;
But the silence was unbroken, and the stillness gave no token,
And the only word there spoken was the whispered word, “Lenore?”
This I whispered, and an echo murmured back the word, “Lenore!”
Merely this, and nothing more.
Back into the chamber turning, all my soul within me burning,
Soon again I heard a tapping somewhat louder than before.
“Surely,” said I, “surely that is something at my window lattice:
Let me see, then, what thereat is, and this mystery explore
Let my heart be still a moment and this mystery explore;
Tis the wind and nothing more!”
Open here I flung the shutter, when, with many a flirt and flutter,
In there stepped a stately Raven of the saintly days of yore;
Not the least obeisance made he; not a minute stopped or stayed he;
But, with mien of lord or lady, perched above my chamber door
Perched upon a bust of Pallas just above my chamber door
Perched, and sat, and nothing more.
Then this ebony bird beguiling my sad fancy into smiling,
By the grave and stern decorum of the countenance it wore.
“Though thy crest be shorn and shaven, thou,” I said, “art sure no craven,
Ghastly grim and ancient Raven wandering from the Nightly shore
Tell me what thy lordly name is on the Night’s Plutonian shore!”
Quoth the Raven, “Nevermore.”
Much I marvelled this ungainly fowl to hear discourse so plainly,
Though its answer little meaning little relevancy bore;
For we cannot help agreeing that no living human being
Ever yet was blessed with seeing bird above his chamber door
Bird or beast upon the sculptured bust above his chamber door, With such name as “Nevermore.”
But the Raven, sitting lonely on the placid bust, spoke only
That one word, as if his soul in that one word he did outpour.
Nothing further then he uttered not a feather then he fluttered
Till I scarcely more than muttered, “Other friends have flown before
On the morrow he will leave me, as my hopes have flown before.”
Then the bird said, “Nevermore.”
Startled at the stillness broken by reply so aptly spoken,
“Doubtless,” said I, “what it utters is its only stock and store,
Caught from some unhappy master whom unmerciful Disaster
Followed fast and followed faster till his songs one burden bore
Till the dirges of his Hope that melancholy burden bore
Of Never nevermore.”
But the Raven still beguiling all my fancy into smiling,
Straight I wheeled a cushioned seat in front of bird, and bust and door;
Then upon the velvet sinking, I betook myself to linking
Fancy unto fancy, thinking what this ominous bird of yore
What this grim, ungainly, ghastly, gaunt and ominous bird of yore
Meant in croaking “Nevermore.”
This I sat engaged in guessing, but no syllable expressing
To the fowl whose fiery eyes now burned into my bosom�s core;
This and more I sat divining, with my head at ease reclining
On the cushion’s velvet lining that the lamp light gloated o�er,
But whose velvet violet lining with the lamp light gloating o�er,
She shall press, ah, nevermore!
Then me thought the air grew denser, perfumed from an unseen censer
Swung by Seraphim whose footfalls tinkled on the tufted floor.
“Wretch,” I cried, “thy God hath lent thee by these angels he hath sent thee
Respite respite and nepenthe, from thy memories of Lenore!
Quaff, oh quaff this kind nepenthe and forget this lost Lenore!”
Quoth the Raven, “Nevermore.”
“Prophet!” said I, “thing of evil! prophet still, if bird or devil!
Whether Tempter sent, or whether tempest tossed thee here ashore,
Desolate yet all undaunted, on this desert land enchanted
On this home by Horror haunted tell me truly, I implore
Is there is there balm in Gilead? tell me tell me, I implore!”
Quoth the Raven, “Nevermore.”
“Prophet!” said I, “thing of evil! prophet still, if bird or devil!
By that Heaven that bends above us by that God we both adore
Tell this soul with sorrow laden if, within the distant Aidenn,
It shall clasp a sainted maiden whom the angels name Lenore
Clasp a rare and radiant maiden whom the angels name Lenore.”
Quoth the Raven, “Nevermore.”
“Be that word our sign in parting, bird or fiend,” I shrieked, upstarting
“Get thee back into the tempest and the Night’s Plutonian shore!
Leave no black plume as a token of that lie thy soul hath spoken!
Leave my loneliness unbroken! quit the bust above my door!
Take thy beak from out my heart, and take thy form from off my door!”
Quoth the Raven, “Nevermore.”
And the Raven, never flitting, still is sitting, still is sitting
On the pallid bust of Pallas just above my chamber door;
And his eyes have all the seeming of a demon’s that is dreaming,
And the lamp light o’er him streaming throws his shadow on the floor;
And my soul from out that shadow that lies floating on the floor
Shall be lifted nevermore!
Program
Topics: Using multiple Lists, Multi-Lists (A list inside a list), Using
multiple interacting classes, Class ArrayList, Class LinkedList,
implementing classes, string manipulations, reading files.
In this class you are going to simulate the creation of a dictionary
using lists to count the frequency that words occur in a file.
To do this you will use a “multi-list” which is the idea of a list, where
each element contains another instance of a list.
You will create an ADT Dictionary which contains a series of “Entries” that represent specific
words and the # of times they occur in the input file.
To accomplish this, you will first create a ADT Entry that contains the information about a word
with the following attributes:
● word – String representing a word in the dictionary
● number of occurrences – the number of times the word occurred as an int.
For Class Entry you will need the following methods:
public Entry( String aWord) : this creates an Entry instance containing the specified word, and
sets the number of occurrences to 1
public String getWord(): This returns the word contained in a given entry.
public int getNumber(): this returns the number of times this word has occurred in the text
public void incrementNumber(): this method adds 1 to the number of occurrences for this
word.
public boolean equals( Entry b): This method overrides the equals method inherited from
class Object. It returns true if the word contained in this entry is the same as the word
contained in the parameter b.
public int compareTo( Entry b): This method compares the words stored in each entry and
calls the compareTo method for class String to correctly order the words in the dictionary.
CLASS ENTRY MUST IMPLEMENT THE COMPARABLE INTERFACE.
Class Dictionary
This class uses class ArrayList which is part of the Java API. Class ArrayList is an
implementation of a List implementing Java’s standard list interface. It encapsulates the
operations for a List we discussed in class, along with many more. See the Java API for a
complete list of ArrayList Operations.
The Dictionary class will have a data member wordList which is an ArrayList of 26 elements
(the number of characters in the alphabet). Each element in the ArrayList will be an instance of
a class doubly linked list whose elements are of type Entry. Words that begin with the letter ‘a’
will be stored in the first element of the “wordList”, words that begin with ‘b’ will be stored in
the second , and so forth. Since array based lists are direct access, this gives you simple
access to the entry for any specific letter!!!!
In addition, the class should have an attribute total that counts the total number of words read
from the file. This is incremented as words are added to the dictionary
Note: As words are read from the input file, you will need to ignore case and special characters.
An easy way to do this is every time you read a word to do:
// the following command removes any non alphabetic characters & replaces them with blanks
aWord = aWord.replaceAll(“[^a-zA-Z]”, ” “);
&
// this command converts a word to all lower case statements
aWord = aWord.toLowerCase();
The first statement replaces all non alphabetic characters with whitespaces. Single quotes are
only used in possessive nouns. After the previous two statements you will need to “trim”
the string to remove any leading or trailing blanks.
Methods for class Dictionary:
● public Dictionary(): Constructor that creates an empty dictionary. It instantiates the
array list of array lists as:
ArrayList wordList = new
ArrayList(26);
●
●
●
public void insert(String word) – a method that stores a word in the dictionary, if it is not
already there. If the word already exists it should update its frequency, and update total.
The linked list must be BUILT in ascending order. When a word is added to the
LinkedList, you must traverse the list to find an entry that either contains the word
being added, OR contains a word greater than the word being added. This is where
you will use the equals and compareTo methods from class Entry.
public void printDictionary(): This method prints out all of the words contained in the
dictionary along with the number of times the word occurred. If no words for a particular
letter exist, print “NO ENTRIES”:. Note you should call the print method for the doubly
linked list.
public void printLetterForward( char letter): Given a letter print all entries for that letter,
alphabetically first to last, along with their count. This should call the printForward method
●
●
●
for the linked list
public void printLetterBackwards( char letter): Given a letter print all entries for that
letter, alphabetically from last to first, along with their count. This should call the
printBackwards method for the linked list.
public boolean contains( String word): This method returns true if the dictionary
contains a specific word
public boolean deleteWord( String word): this method removes an entry from the
dictionary and returns true if the word is present in the dictionary, and false if the word is
not in the dictionary.
Example of printing ALL OF THE WORDS IN THE SORTED DICTIONARY ALONG WITH
THEIR FREQUENCY:
a
any
apple
candle
cat
…….
1000
534
10
5
45
Class: DoubleLinkedList:
For this project, you must finish the implementation of a doubly linked list. The specification is
given is given below:
Generic doubly linked List
// FOR THIS CLASS YOU MAY TAKE INSPIRATION FROM MY
// LECTURE ON THE DOUBLY LINKED DATA STRUCTURES
public class DoublyLinkedList implements MyList
Node head; // list data member
Node tail; // list data member
int currentSize;
// below is the inner node class
class Node{
S item;
Node next;
Node prev;
public Node( S value){
item = value;
next = null;
prev = null;
}
public Node( S value, Node nxt, Node prv){
item = value;
next = nxt;
prev = prv;
}// end class NODE
// implement these methods for the doubly linked list.
public List ()
//Description: This constructor creates a new list object, setting the current size to zero, head to null, &
tail to null
public boolean isEmpty()
// description: this method returns true if the list contains zero elements
public int size():
//Description: Returns the number of entries the list contains
public void add( S value)
// Description: This method inserts a new element into the linked list in ASCENDING order
public void remove(S value);
// This method removes an entry from the list
public int find( S value):
// Description: this method returns the position number of the first element
// in the list containing the specified value.
public int get ( int position)
//Description: returns the value stored in element position.
public void clear ( int position)
//Description: deletes all elements from the list
Tester Class : Main Method
Also write a tester class containing a main method. In the main method which read words
one at a time from a tester file. Your main method must:
•
•
•
Create an instance of your dictionary.
Prompt the user for the name of a data file and open a Scanner attached to the
data file
Read words one at a time from the data file: [HINT: try something like]
while (dataFile.hasNextLIne() ){
nextWord = dataFile.next();
// then add the word to the dictionary using the method “insert”
}
Once all words are read and added to the dictionary:
call the printLetterForward for each of the letters: ‘a’, ‘h’, ‘p’
call the printLetterBackward for each of the letters: ‘a’, ‘h’, ‘p’
call the contains method for the words “and” & “zebra” and print out the result.
call the removeWord method to remove the word “and” from the dictionary
Finally call the printDictionary method
What to submit: zip and submit your test
program, your Dictionary class, your Entry
class, your DoublyLinkedList class