You are on page 1of 1

// postcondition: returns the number of words in this WordList that

// are exactly len letters long


public int numWordsOfLength(int len)
{
int counter = 0;
for (String str : myList)
if (str.length() == len)
counter++;
return counter;
}
// postcondition: all words that are exactly len letters long
// have been removed from this WordList, with the
// order of the remaining words unchanged
public void removeWordsOfLength(int len)
{
for (int i = myList.size(); i >= 0; i--)
if ((myList.get(i)).length() == length)
myList.remove(i);
}
public class Cat extends Pet
{
public Cat(String name)
{
super(name);
}
public String speak()
{
return "meow";
}
}
public class LoudDog extends Dog
{
public LoudDog(String name)
{
super(name);
}
public String speak()
{
return super.speak() + " " + super.speak();
}
}
// postcondition: for each Pet in the kennel, its name followed
// by the result of a call to its speak method
// has been printed, one line per Pet
public void allSpeak()
{
for (Pet p : petList)
{
System.out.println(p.getName + " " + p.speak());
}
}

You might also like