CS49J

Remember not to create packages. Use the default package

16A

Write a class, TextCondensor, whose constructor takes an ArrayList<String> as a parameter.

Provide methods:

Here are the files you will need:

humpty.txt:

Humpty Dumpty sat on a wall,
Humpty Dumpty had a great fall.
All the king's horses and all the king's men
Couldn't put Humpty together again.

mary.txt:

Mary had a little lamb, little lamb,
little lamb, Mary had a little lamb
whose fleece was white as snow.
And everywhere that Mary went
Mary went, Mary went, everywhere
that Mary went
The lamb was sure to go.

He followed her to school one day,
school one day, school one day,
He followed her to school one day,
Which was against the rules,
It made the children laugh and play,
laugh and play, laugh and play,
It made the children laugh and play,
To see a lamb at school.

And so the teacher turned it out,
turned it out, turned it out,
And so the teacher turned it out,
But still it lingered near,
He waited patiently about,
ly about, ly about,
He waited patiently about,
Till Mary did appear.

"Why does the lamb love Mary so?"
love Mary so?" love Mary so?"
"Why does the lamb love Mary so?"
The eager children cried.
"Why, Mary loves the lamb, you know,"
lamb, you know," lamb, you know,"
"Why, Mary loves the lamb, you know,"
The teacher did reply

 

Codecheck URL

16B

The sieve of Earthosthenes is an algorithm for finding all the prime numbers less that or equal to a given integer. With a piece of paper the process would be:

Write down all the numbers less than or equal to n. Cross out all the multiples of 2 (except 2) Cross out all the multiples of 3 ... up to the square root of n.

This URL http://www.javawithus.com/programs/sieve-of-eratosthenes explains the algorithm. There are lots of websites(including this one) that implement this algorithm using arrays. Don't just copy this code. You are to use a set in your implementation.

You are to write a class Sieve.

It has a constructor that takes as a parameter the upper limit for the primes

It has methods

 

Codecheck URL