Question: Language Scala Method: In a package named rdm create Scala class named Word with the following: A constructor that takes a value of type List
Language Scala
Method: In a package named "rdm" create 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.
For more information on sounds, see the Rhyming Dictionary HW handout.
A method named "alliterationLength" that takes a Word as a parameter and returns an Int. This method returns the number of sounds at the beginning of the 2 words that match.
Ex. The Lists of sounds:
List("K", "AH0", "L", "AE1", "M", "AH0", "T", "AH0", "S"),
List("K", "AH0", "L", "IH1", "P", "S", "OW2")
have an alliteration length of 3 since the first 3 sounds areidentical
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 anotherword. 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 createdfrom 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. To iterate 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. I
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
