public WordPairList(String words)
allPairs = new ArrayList<WordPair>();
for (int i = 0; i < words.length - 1; i++)
for (int j = i+1; j < words.length; j++)
allPairs.add(new WordPair(words[i], words[j]));
public int numMatches()
int count = 0;
for (WordPair pair : allPairs)
if (pair.getFirst().equals(pair.getSecond())) 1
WordPair class in the question does not show or mention any fields.
Fields are required to hold the first and the second words of the pair, and these fields must be private.
private String first, second;
private String words;
Regardless of how the fields are defined in
WordPair, you cannot refer to them directly in your solution
WordPairList code because the fields are private in
You must call the
getLast accessor methods.
Copyright © 2018 by Skylight Publishing