WordPairList had you work with an
For part A you implemented a constructor that went through an array of strings. Each element of the array was paired up with each element that followed to create an
For example, if
["hi", "there", "bob", "smith"] you would fill
["there", "smith"], and
The way I solved this was with a nested loop. The first loop takes you from 0 to the end. The second starts one to the right of the first and goes to the end.
In part B you needed to count how many
WordPair references in
allPairs contained the same first and second word. It’s checking that you know how to iterate through an
ArrayList, that you can get a single object out of the list, and that you know to use the
equals method instead of
== on strings.
Want to stay in touch and keep up to date with the latest posts @ CompSci.rocks?