Implement the PictureBook class. A skeleton can be found here. The API can be found here. A jar with the Book class can be found here.
package test4;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;
/**
* A picture book is a special type of book.
* Each picture book has a collection of pictures.
* The picture book and the collection of pictures
* form a composition.
*/
public class PictureBook extends Book
{
private List<ImageIcon> pictures;
/**
* Initializes this picture book with the given title and
* collection of pictures.
*
* @param title the title of this picture book.
* @param pictures the collection of pictures of this picture book.
* @pre. pictures != null
*/
public PictureBook(String title, List<ImageIcon> pictures)
{
super(title);
this.setPictures(pictures);
}
/**
* Initializes this picture book with the title and collection
* of picture of the given other picture book.
*
* @param book another picture book.
* @pre. book != null
*/
public PictureBook(PictureBook book)
{
super(book);
this.setPictures(book.getPictures());
}
/**
* Returns the collection of pictures of this picture book.
*
* @return the collection of pictures of this picture book.
*/
public List<ImageIcon> getPictures()
{
List<ImageIcon> pictures = new ArrayList<ImageIcon>();
for (ImageIcon picture : this.pictures)
{
ImageIcon copy = new ImageIcon(picture.getImage());
pictures.add(copy);
}
return pictures;
}
/**
* Sets the collection of pictures of this picture book to the
* given collection of pictures.
*
* @param pictures the collection of pictures of this picture book.
* @pre. pictures != null
*/
public void setPictures(List<ImageIcon> pictures)
{
this.pictures = new ArrayList<ImageIcon>();
for (ImageIcon picture : pictures)
{
ImageIcon copy = new ImageIcon(picture.getImage());
this.pictures.add(copy);
}
}
/**
* Returns a string representation of this picture book.
* This string representation consists of "The book entitled "
* followed by the title of this book, followed by " with ",
* followed by the number of picture, followed by " pictures".
*
* @return a string representation of this picture book.
*/
public String toString()
{
return super.toString() + " with " + this.getPictures().size() + " pictures";
}
}