Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language scala create a Scala class named Word with the following: A constructor that takes a value of type List of Strings representing the sounds

Language scala

create a Scala class named Word with the following: A constructor that takes a value of type List of Strings representing the sounds of the word with each sound as a separate element in the list.

Amethodnamed"alliterationLength"thattakesaWordasaparameterand returns an Int. This method returns the number of sounds at the beginning of the 2 words that match.

Ex.TheListsofsounds

  • List("K", "AH0", "L", "AE1", "M", "AH0", "T", "AH0", "S"), and

  • List("K", "AH0", "L", "IH1", "P", "S", "OW2")

  • have an alliteration length of 3 since the first 3 sounds are identical

  • Testing: : In a package named "tests" create a Scala class named "TestWords" as a test suite that tests the functionality listed above.

Notes and Implications

  • A Word with an empty list of sounds always has iteration length 0 with other words.

  • An entire word can be part of the alliteration of another word.

    Ex. "home"/List("HH", "OW1", "M") and "homework"/List("HH", "OW1", "M", "W", "ER2", "K"))

  • Since alliterationLength is part of the behavior of the new objects created from the Word class, it has access to the list of sounds from the constructor call by using the keyword "this.

    Compare "this" list of sounds with the sounds of the input of the method.

  • Toiterate over 2 Lists simultaneously you can iterate over the indices of the lists and call the apply method on each list to access the appropriate elements on each iteration of your loop.

  • The list of sounds in the constructor does not have a defined name.

    DO NOT access the list of sounds in your tests. In all likelihood, our code on AutoLab will have adifferentnamethantheoneyouchoseandyourtestswill causeerrors.

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

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

fscanf retums a special value EOF that stands for...

Answered: 1 week ago