From ef280a746656e260677f9ebf8bdc9e2f4d5040e9 Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Mon, 27 Oct 2025 14:14:14 -0700 Subject: [PATCH] add comments to lab04 --- src/code/ca/bcit/comp2522/lab04/Author.java | 3 ++ .../ca/bcit/comp2522/lab04/Autobiography.java | 3 ++ .../ca/bcit/comp2522/lab04/Biography.java | 31 +++++++++----- src/code/ca/bcit/comp2522/lab04/Book.java | 12 ++++++ src/code/ca/bcit/comp2522/lab04/Main.java | 11 +++++ src/code/ca/bcit/comp2522/lab04/Name.java | 11 ++++- src/code/ca/bcit/comp2522/lab04/Person.java | 42 ++++++++++++++++++- 7 files changed, 99 insertions(+), 14 deletions(-) diff --git a/src/code/ca/bcit/comp2522/lab04/Author.java b/src/code/ca/bcit/comp2522/lab04/Author.java index 06a21a6..530e19d 100644 --- a/src/code/ca/bcit/comp2522/lab04/Author.java +++ b/src/code/ca/bcit/comp2522/lab04/Author.java @@ -36,6 +36,9 @@ public class Author extends Person implements Printable this.genre = genre; } + /** + * display formatted information about the Author + */ @Override public void display() { diff --git a/src/code/ca/bcit/comp2522/lab04/Autobiography.java b/src/code/ca/bcit/comp2522/lab04/Autobiography.java index 51b0964..e63b74f 100644 --- a/src/code/ca/bcit/comp2522/lab04/Autobiography.java +++ b/src/code/ca/bcit/comp2522/lab04/Autobiography.java @@ -26,6 +26,9 @@ public class Autobiography extends Biography implements Printable super(title, year, author, author); } + /** + * display formatted information about the Autobiography + */ @Override public void display() { diff --git a/src/code/ca/bcit/comp2522/lab04/Biography.java b/src/code/ca/bcit/comp2522/lab04/Biography.java index 4be4736..b172dc1 100644 --- a/src/code/ca/bcit/comp2522/lab04/Biography.java +++ b/src/code/ca/bcit/comp2522/lab04/Biography.java @@ -11,7 +11,7 @@ package ca.bcit.comp2522.lab04; */ public class Biography extends Book implements Printable { - final Person subject; + private final Person subject; /** * Biography constructor @@ -33,26 +33,30 @@ public class Biography extends Book implements Printable this.subject = subject; } + /** + * equals checks if a given object is equal to this object + * @param o the reference object with which to compare. + * @return if the given object is equal + */ @Override public boolean equals(final Object o) { - if (o == null || getClass() != o.getClass()) + if (o == null || !this.getClass().equals(o.getClass())) { return false; } - Biography other; + final Biography other; other = (Biography)o; - if (this == o) - { - return true; - } - - return this.subject.equals(other.subject); + return this.subject.equals(other.getSubject()); } + /** + * hashCode gives the hashcode of the biography + * @return hash code of biography + */ @Override public int hashCode() { @@ -63,11 +67,12 @@ public class Biography extends Book implements Printable return subject.hashCode(); } - + /** + * display formatted instance variable of the biography + */ @Override public void display() { - final StringBuilder builder; builder = new StringBuilder(); @@ -83,4 +88,8 @@ public class Biography extends Book implements Printable System.out.println(builder.toString()); } + + public Person getSubject() { + return this.subject; + } } diff --git a/src/code/ca/bcit/comp2522/lab04/Book.java b/src/code/ca/bcit/comp2522/lab04/Book.java index edea15c..95040ea 100644 --- a/src/code/ca/bcit/comp2522/lab04/Book.java +++ b/src/code/ca/bcit/comp2522/lab04/Book.java @@ -42,6 +42,9 @@ public class Book this.author = author; } + /** + * display formatted instance data of the book + */ @Override public void display() { @@ -60,6 +63,9 @@ public class Book System.out.println(builder.toString()); } + /** + * backward prints the name of the title in reverse + */ @Override public void backward() { @@ -71,6 +77,12 @@ public class Book System.out.println(builder.toString()); } + /** + * compareTo another book, books are equal if they are written in the same + * year + * @param other book to compare to + * @return if the given book is older, newer or same age as this book + */ @Override public int compareTo(final Book other) { diff --git a/src/code/ca/bcit/comp2522/lab04/Main.java b/src/code/ca/bcit/comp2522/lab04/Main.java index a04292e..1adf529 100644 --- a/src/code/ca/bcit/comp2522/lab04/Main.java +++ b/src/code/ca/bcit/comp2522/lab04/Main.java @@ -1,6 +1,17 @@ package ca.bcit.comp2522.lab04; +/** + * Main program driver class + * @author Braeden Sowinski + * @author Nico Agostini + * @author Trishaan Shetty + * @version 1.0.0 + */ public class Main { + /** + * main program entry + * @param args from the cli + */ public static void main(final String[] args) { // ------------------------------------------------------------- diff --git a/src/code/ca/bcit/comp2522/lab04/Name.java b/src/code/ca/bcit/comp2522/lab04/Name.java index 808a73c..9665136 100644 --- a/src/code/ca/bcit/comp2522/lab04/Name.java +++ b/src/code/ca/bcit/comp2522/lab04/Name.java @@ -12,11 +12,11 @@ package ca.bcit.comp2522.lab04; */ public class Name implements Printable { + private static final int MAX_NAME_CHARACTERS = 50; + private final String first; private final String last; - private static final int MAX_NAME_CHARACTERS = 50; - /** * Name constructor * @param first name to save @@ -31,10 +31,17 @@ public class Name implements Printable this.last = last; } + /** + * getFullName includes the first and last name + * @return first name and last name + */ protected String getFullName(){ return this.first + " " + this.last; } + /** + * display the full name, first and last + */ @Override public void display() { diff --git a/src/code/ca/bcit/comp2522/lab04/Person.java b/src/code/ca/bcit/comp2522/lab04/Person.java index fe538e4..18ce5e0 100644 --- a/src/code/ca/bcit/comp2522/lab04/Person.java +++ b/src/code/ca/bcit/comp2522/lab04/Person.java @@ -16,6 +16,8 @@ public class Person Printable, Reversible { + private static final int SUCCESSFUL_MATCH = 0; + protected final Date dateOfBirth; protected final Date dateOfDeath; protected final Name name; @@ -39,10 +41,25 @@ public class Person this.name = name; } + /** + * getFullName of the Person + * @return the full name + */ public String getFullName(){ return this.name.getFullName(); } + /** + * getDateOfBirth of person + * @return the date of birth of the person + */ + public Date getDateOfBirth() { + return this.dateOfBirth; + } + + /** + * display formatted instance data of the person + */ @Override public void display() { @@ -60,6 +77,9 @@ public class Person System.out.println(builder.toString()); } + /** + * backward version of the full name + */ @Override public void backward() { @@ -72,9 +92,29 @@ public class Person System.out.println(builder.toString()); } - + /** + * compareTo another person based on date of birth + * @param other person to compare + * @return if a person is older, younger or same age + */ @Override public int compareTo(final Person other) { return this.dateOfBirth.compareTo(other.dateOfBirth); } + + /** + * equals checks if another given object is equal to this object + * @param o the reference object with which to compare. + * @return if given object are equals + */ + public boolean equals(final Object o) { + if (o == null || !this.getClass().equals(o.getClass())) { + return false; + } + + final Person p = (Person)o; + + return p.getFullName().equals(this.getFullName()) && + this.getDateOfBirth().compareTo(p.getDateOfBirth()) == SUCCESSFUL_MATCH; + } }