Overview in this assignment you are provided with an

Assignment Help JAVA Programming
Reference no: EM13346559

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: EM13346559

Questions Cloud

Task 1go to httppricespyconz httpwwwbuildtoorderpccom or : task 1go to httppricespy.co.nz httpwww.buildtoorderpc.com or any another source that identifies the cost of computer
Problem 1segregation of duties in the personal computing : problem 1segregation of duties in the personal computing environmentwhat role should the hr organization play in this
The epa estimates that the average motor vehicle in america : the epa estimates that the average motor vehicle in america is driven 12000 miles per year epa.gov. fuel efficiencies
1nbspnbspnbspnbspnbsp ernest inc has identified the : 1.nbspnbspnbspnbspnbsp ernest inc. has identified the following overhead costs and cost drivers for next
Overview in this assignment you are provided with an : overview in this assignment you are provided with an interface that contains a generic type.you are asked to create two
Assessment item 3 this is an individual assessment and : assessment item 3 this is an individual assessment and requires you to produce a timely assignment of high quality. you
Question 1 nbspexplain each of the following using supply : question 1 nbspexplain each of the following using supply and demand diagrams.awhen a cyclone hits queensland the price
Consideration does not have to be adequate or commercially : consideration does not have to be adequate or commercially realistic nor does it need to be expressed in monetary terms
Technological innovations have taken the world by a : technological innovations have taken the world by a storm.nbsp the base of innovation has been extremely expeditious

Reviews

Write a Review

JAVA Programming Questions & Answers

  Study the code and implement the operator overloading

The Table Q3 on the next page is the code of a class named Circle. Study the code and implement the operator overloading for these relational operators ( , >=) for the Circle class. Then, write a test program that creates two instances of the Circle ..

  Menu based program to maintain student records

Write a menu based program to maintain student records. Your program should take the following inputs: 1. Student first name (max. 20 characters) 2. Student last name, (max. 20 characters) 3. Student scores (float/double), eg. 85.4 Problem

  Produce a design document

You will design and deliver a website foes fictional client part-1 Website Design Document and produce a design document

  Which a ball is released from a user-defined height

Write a program in which a ball is released from a user-defined height and free-falls to the ground. The ball is pulled by earth's gravity of 9.8 m/sec 2 . Assume that each pixel represents

  Use inheritance to read, store, and print questions for test

use inheritance to read, store, and print questions for a test. First, write an abstract class

  Write an application with three labeled text field

Write an application with three labeled text fields,one each for the initial amount of a savings account, the annual interest rate, and the number of years. Add a button "Calculate" and a read-only text area to display the balance of the savings acco..

  Write a method called alldigitsodds that returns

Write a method called AllDigitsOdds that returns whether every digit of a positive integer is odd. Return true if the numbers consist entirely of odd digits (1,3,5,7,9)

  Write java program to reverse contents of original array

Write down the Java program method named reversal which returns the new array which is a reversal of original array. Use [5.0, 4.4, 1.9, 2.9, 3.4, 3.5] to test method.

  Organization structure change over time

How and why did the organization structure change over time, and in what ways were some of these changes responsible for some of their recent problems?

  Java threads

This is an introductory assignment on Java synchronization. You will use Java Threads while learning more about concurrency and achieving atomicity using Java’s inbuilt mechanisms.

  Program that counts the number of occurrences of lowercase

Write a program that counts the number of occurrences of lowercase and uppercase vowels in entered lines of text. Use a two-dimensional array to store the vowel counts. The array's first column holds the counts for the lowercase vowels, and the secon..

  Java class to accept a user-s hourly rate of pay

Write a class that accepts a user's hourly rate of pay and the number of hours worked. Display the user's gross pay, the withholding tax (15% of gross pay), and the net pay (gross pay - withholding).

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