Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java assignment: A sentence in English is made of several words in a particular sequence. You must represent such a sentence as a list of

Java assignment:

A sentence in English is made of several words in a particular sequence. You must represent such a sentence as a list of words. Much like the list example we saw in class, this one is made of nodes (represented by a Sentence interface). There is one word per node, called WordNode. The sentence may also contain zero or more punctuation marks, which are represented by a PunctuationNode. The end of the sentence is denoted by a special empty node, called EmptyNode.

Define the following operations for such a list of words:

A method getNumberOfWords that computes and returns the number of words in a sentence. The punctuation does not count as a word.

A method String longestWord that determines and returns the longest word in a sentence. The longest word should not begin or end with punctuation.

A method toString that will convert the sentence into one string. There must be a space between every two words. There is no space between the last word and the end of this sentence. If there is no punctuation mark at the end of the sentence, this string should end with a period (it shouldnt add the period to the original sentence)

A method Sentence clone() that returns a duplicate of a given sentence. A duplicate is a list that has the same words and punctuation in the same sequence, but is independent of the original list.

A method Sentence merge(Sentence other) that will merge two sentences into a single sentence. The merged list should preserve all the punctuation. The merged list should be returned by this method, and the original lists should be unchanged.

Design the interfaces and classes that you need for this purpose.

In a JUnit test class, create examples of sentences and write tests for each operation.

Design the fields and methods for your classes, and verify that your tests pass on them.

Check if you can abstract any common parts of your design/code. If so, take a "bottom up" approach and push these common features into an appropriate superclass.

Sentence Interface:

import java.util.ArrayList;

public interface Sentence { ArrayList words = null; /* Computes and returns the number of words in a sentence. * The punctuation does not count as a word. */ public int getNumberOfWords(); /* Determines and returns the longest word in a sentence. * The longest word should not begin or end with punctuation. */ public String longestWord(); /* Convert the sentence into one string. * There must be a space between every two words. * There is no space between the last word and the end of this sentence. * If there is no punctuation mark at the end of the sentence, this * string should end with a period (it shouldnt add the period to the * original sentence). */ public String toString(); /* Returns a duplicate of a given sentence. A duplicate is a * list that has the same words and punctuation in the same * sequence, but is independent of the original list. */ public Sentence clone(); /* Merge two sentences into a single sentence. The merged list * should preserve all the punctuation. The merged list should * be returned by this method, and the original lists should be * unchanged. */ public Sentence merge(Sentence other);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What do you dislike about Presidential debates?

Answered: 1 week ago

Question

Prepare an electronic rsum.

Answered: 1 week ago

Question

Strengthen your personal presence.

Answered: 1 week ago

Question

Identify the steps to follow in preparing an oral presentation.

Answered: 1 week ago