import java.util.* ; import java.io.* ; class Driver { public static void main ( String args[] ) throws Exception { Scanner s = null ; String tempName = "" ; int count = 0 ; int tempAge ; int tempTraining ; int tempId ; Dog tempDog ; LinkedList dogList = new LinkedList() ; for (int i = 1 ; i <= 50 ; i++) { tempName = "spot"+i ; tempDog = new Dog(tempName, 1000+i, i, 5) ; dogList.add(tempDog) ; } // Print out all the dogs System.out.println("All the dogs to start with") ; Iterator i = dogList.iterator() ; while (i.hasNext()) { tempDog = (Dog) i.next() ; tempDog.Print() ; } // increase trained level by 2 for all dogs whose age is < 20 i = dogList.iterator() ; while (i.hasNext()) { tempDog = (Dog) i.next() ; if (tempDog.getAge() < 20) tempDog.setTrainedLevel( tempDog.getTrainedLevel() + 2) ; } // decrease trained level by 1 for all dogs whose ownerId is >= 20 and <= 30 i = dogList.iterator() ; while (i.hasNext()) { tempDog = (Dog) i.next() ; if ( (tempDog.getOwnerId() <= 1030) && (tempDog.getOwnerId() >= 1010) ) tempDog.setTrainedLevel( tempDog.getTrainedLevel() - 1) ; } // Print out all the dogs System.out.println("All the dogs after BOTH sets of changes") ; i = dogList.iterator() ; while (i.hasNext()) { tempDog = (Dog) i.next() ; tempDog.Print() ; } System.out.println("Doing the removals") ; // create a second list LinkedList list2 = new LinkedList() ; // add any of the dogs you do NOT want to remove to the second list i = dogList.iterator() ; while (i.hasNext()) { tempDog = (Dog) i.next() ; // notice the "!" at the start of the if clause, these NOT ones are the ones to keep if ( !((tempDog.getTrainedLevel() >5 ) && (tempDog.getOwnerId() < 1030) ) ) { list2.add(tempDog) ; } } // make the dogList equal to this new second list dogList = list2 ; // print out all the dogs System.out.println("All the dogs after the removals") ; i = dogList.iterator() ; while (i.hasNext()) { tempDog = (Dog) i.next() ; tempDog.Print() ; } } }