Interfaces and generics, JAVA Programming

Assignment Help:

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.


Related Discussions:- Interfaces and generics

Why is uml important? , The more complicated the underlying system, the mor...

The more complicated the underlying system, the more critical the inter communication among everyone involved in deploying and developing the software. UML is a software language f

Pattern printing program, Question Using 3 level of nested for loop, writ...

Question Using 3 level of nested for loop, write a program that will produce the output as below.

Java identifiers, 1. Which of the following are not valid Java identifiers,...

1. Which of the following are not valid Java identifiers, and why? (a) wolVes (b) United(there is only one) (c) 87 (d) 5 3 (e) Real ale (f) isFound?by 2. A cla

Project, Hey, i have a project on java can you help me

Hey, i have a project on java can you help me

Develop a java application, Modules of software: 1 - Serial RS232 comm p...

Modules of software: 1 - Serial RS232 comm port comunication 2 - NanoHTTPD serving some processed pages 3 - System tray application to indicate status and access configura

Describe the java collections framework? , Comparable interface: The "Com...

Comparable interface: The "Comparable" allows itself to compare with other same types of object. The function compareTo() is specified in the interface. Several of the standa

How to integrate your struts application with spring, To integrate your Str...

To integrate your Struts application with Spring, we have two options: ? Configure Spring to manage your Actions as beans, using the ContextLoaderPlugin, and set their dependenc

I want an idea for final year projects, i m confused what to take as a pro...

i m confused what to take as a project for final year in information tech cn u suggest some of the topic of software

Defiine the term object, Defiine the term Object ? Object is a named co...

Defiine the term Object ? Object is a named collection of properties (data, state) & techniques (instructions, behavior). Mainly Objects are key to understanding object-oriente

Online Music Store, Online music store that stores information about song, ...

Online music store that stores information about song, artist, album, customer, playlist. Also all necessary diagrams - use case, uml, erd

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd