Create classes implement java interface

Assignment Help JAVA Programming
Reference no: EM13448

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<T>
{
public T getFirst();
public T getLast();
public ArrayList<T> 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<Character> 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<Character> 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<Character>.

? 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<Word> 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<Word>.

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<Word>. 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<Word>.

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.

Reference no: EM13448

Questions Cloud

Identifies the cost of computer : identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:
Segregation of duties in the personal computing environment : Why is inadequate segregation of duties a problem in the personal computing environment?
Calculate the gasoline savings : How much gasoline do vehicles with the following fuel efficiencies consume in one year? Calculate the gasoline savings, in gallons per year, created by the following two options. Show all your work, and draw boxes around your answers.
Compute the pool rates for the different activities : Complete the schedule to compute the pool rates for the different activities.
Create classes implement java interface : Interface that contains a generic type. Create two classes that implement this interface.
Required to undertake a strategic analysis of organisation : Drawing from your discussion of Question 1, provide a brief analysis of SWOT (Strengths, Weaknesses, Opportunities, and Threats) of the company chosen. Before the brief analysis, discuss what SWOT is and how it is  important.
Supply and demand diagrams : Explain each of the following using supply and demand diagrams,  With the use of a graph, explain how these two programs affect cigarette consumption and the price of cigarettes.
Discuss the accuracy of this statement : 'Consideration does not have to be adequate or commercially realistic, nor does it need to be expressed in monetary terms, it merely needs to be "sufficient".' Discuss the accuracy of this statement.
Evaluate models of diffusion and intention : Analyze the forces that impact on - and the measures that justify - technology decisions, Critically evaluate models of diffusion and intention and actuality of use

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

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