Groovy Excercise -12

class Book {
def title
def author
def isbn

@Override
String toString({
  "$title : $author"
}

}


def books []

def book1 new Book(title"The Curious Gardener"author"Pavord, Anna"isbn"1408810069")
def book2 new Book(title"Paradise Postponed"author"Mortimer, John"isbn"0141193395")
def book3 new Book(title"The Sport of Olympic-Style Weightlifting"author"Miller, Carl"isbn"0865348111")

books << book1 << book2 << book3 

println "Original Book List size >>> "books.size()

//edit our list of books to keep only those with the word "The" in the title
books.retainAll {it.title.contains("The")}
println " Book List size >>> "books.size()

//edit our list of books to remove any by authors with names beginning with M
books.removeAll {it.author[0== "P"}
println " Book List size >>> "books.size()

println "There are ${books.size()} books left:"
books.each {println it}
             

Output of Script

 300 ms

Original Book List size >>> 3
Book List size >>> 2
Book List size >>> 1
There are 1 books left:
The Sport of Olympic-Style Weightlifting : Miller, Carl
 [The Sport of Olympic-Style Weightlifting : Miller, Carl] java.util.ArrayList

Comments

Popular posts from this blog

தட்டு வண்டியில் காளிக்கோயில் - சிறுகதை

பிரேமாவின் பெண் குழந்தை

தீபம் பிளக்ஸ்