WordPairList had you work with an ArrayList of WordPair objects.

Part A

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 ArrayList of WordPair references.

For example, if words contained ["hi", "there", "bob", "smith"] you would fill allPairs with ["hi", "there"], ["hi", "bob"], ["hi", "smith"], ["there", "bob"], ["there", "smith"], and ["bob", "smith"].

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.

Part B

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.

Why ClassCube?

Are you spending too much time grading your students' source code?

ClassCube is an online tool for Computer Science teachers that allows you to create lab assignments for your students. They'll submit their code online and ClassCube will automatically grade it for you.

Teaching with ClassCube…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>