This repository acts as a personal archive for my solutions to EdX course *Data Structures and Software Design* from PennX.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB

  1. /*
  2. * SD2x Homework #9
  3. * This class represents a newspaper article.
  4. * Refactor the code according to the suggestions in the assignment description.
  5. */
  6. import java.util.*;
  7. public class NewspaperArticle extends Document{
  8. private int startPage;
  9. private int endPage;
  10. private String newspaper;
  11. private Set<String> editors;
  12. public NewspaperArticle(String title, String author, int startPage, int endPage, Set<String> editors, String newspaper, Date date, String city, String state, String postCode) {
  13. super(title, author, date, city, state, postCode);
  14. this.startPage = startPage;
  15. this.endPage = endPage;
  16. this.newspaper = newspaper;
  17. this.editors = editors;
  18. }
  19. public int getStartPage() {
  20. return startPage;
  21. }
  22. public int getEndPage() {
  23. return endPage;
  24. }
  25. public String getNewspaper() {
  26. return newspaper;
  27. }
  28. public int numPages(){
  29. return endPage - startPage + 1;
  30. }
  31. public boolean sameNewspaper(NewspaperArticle article) {
  32. return this.newspaper.equals(article.newspaper);
  33. }
  34. public Set<String> getEditors() {
  35. return editors;
  36. }
  37. public int numEditors(){
  38. return editors.size();
  39. }
  40. public Set<String> commonEditors(NewspaperArticle article){
  41. Set<String> sameEditors = new HashSet<String>();
  42. for(String ed : article.editors){
  43. if(this.editors.contains(ed)){
  44. sameEditors.add(ed);
  45. }
  46. }
  47. return sameEditors;
  48. }
  49. }