/* * SD2x Homework #9 * This class represents a newspaper article. * Refactor the code according to the suggestions in the assignment description. */ import java.util.*; public class NewspaperArticle extends Document{ private int startPage; private int endPage; private String newspaper; private Set editors; public NewspaperArticle(String title, String author, int startPage, int endPage, Set editors, String newspaper, Date date, String city, String state, String postCode) { super(title, author, date, city, state, postCode); this.startPage = startPage; this.endPage = endPage; this.newspaper = newspaper; this.editors = editors; } public int getStartPage() { return startPage; } public int getEndPage() { return endPage; } public String getNewspaper() { return newspaper; } public int numPages(){ return endPage - startPage + 1; } public boolean sameNewspaper(NewspaperArticle article) { return this.newspaper.equals(article.newspaper); } public Set getEditors() { return editors; } public int numEditors(){ return editors.size(); } public Set commonEditors(NewspaperArticle article){ Set sameEditors = new HashSet(); for(String ed : article.editors){ if(this.editors.contains(ed)){ sameEditors.add(ed); } } return sameEditors; } }