Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Overview: In this assignment, you are provided with an interface that contains a generic type.

You are asked to create two classes that implement this interface.

A. The Sequenced Interface

In the provided code, you are given an interface called Sequenced that is used by classes that have a sequential structure to them. The interface is short, containing only 3 abstract methods.

In fact, the interface in its entirety can be shown here:

import java.util.ArrayList;

public interface Sequenced
{
public T getFirst();
public T getLast();
public ArrayList getSequence();
}

You will be creating two classes that each implement Sequenced, and so each of them must contain implementations of these 3 methods.

You will notice that Sequenced has a generic type parameter T. Your subclass definitions will each need to instantiate T when they implement the interface.

B. The Word Class

You should create a class Word that represents words in a language. Word implements the Sequenced interface, because a word is a sequence of characters. The Word class should have two instance fields:

? An instance field of type ArrayList which will store a word's character sequence. Note: Java has a Character wrapper class that you should use here.

? An instance field of type int, representing the Word's position in the sentence (with the first Word in a sentence being position 0).
Word should have the following methods:

? The getFirst() method should return the first Character of the word,

? the getLast() method should return the last Character of the word,

? getSequence() should return an ArrayList of all the characters, and

? getPosition() should return the int representing the Word's position in the sentence Based on the previous two paragraphs, it should be clear to you how Word instantiates the T parameter when it implements the Sequenced interface. If not, here is a hint: look at the Sequenced interface and notice the use of T in the return types of the methods. Then think about what the Word class is going to return in each of the methods.

The Word constructor should take two parameters:

? it should take a String parameter and add the individual Characters of the String to the ArrayList.

? it should take an int parameter representing the position of the Word in a sentence and set the relevant instance field accordingly.

C. The Sentence Class

You should create a second class Sentence that represents sentences in a language. Sentence implements the Sequenced interface, because a sentence is a sequence of words. Sentence should have a single instance field of type ArrayList which will store the Words of a sentence. This relationship between the Sentence and Word classes is called composition, because a Sentence is composed of Words. Note that there is NOT an inheritance relationship between Sentence and Word.Sentence should have the following methods:

? The getFirst() method should return the first Word of the Sentence,

? the getLast() method should return the last Word of the Sentence, and

? getSequence() should return an ArrayList.

Based on the previous two paragraphs, it should be clear to you how Sentence instantiates the T parameter when it implements the Sequenced interface. If not, here is a hint: look at the Sequenced interface and notice the use of T in the return types of the methods. Then think about what the Sentence class is going to return in each of the methods.

The Sentence constructor should take a single String parameter representing the

Sentence, and add each Word of the sentence to the ArrayList. You can split the String into Words by using the String split() method in the following way:

String[] spl = s.split("\\s+");

Notice that the split() method will give you an array of Strings, and you will need to go through that array, creating Words and adding them to the ArrayList.

D. SequenceTester Class

A tester class is provided for you, demonstrating how Sentence and Word can be used and indicating what the output should be.

Java, Programming

  • Category:- Java
  • Reference No.:- M9130911
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Java

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As