add comments to lab04

This commit is contained in:
SowinskiBraeden committed 2025-10-27 14:14:45 -07:00
1 parent f168656585
commit ef280a7466
7 files changed
+99 -14

No files matched your search

@@ -36,6 +36,9 @@ public class Author extends Person implements Printable
this.genre = genre;
}
/**
* display formatted information about the Author
*/
@Override
public void display()
{
@@ -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()
{
+20 -11
View File
@@ -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;
}
}
+12
View File
@@ -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)
{
+11
View File
@@ -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) {
// -------------------------------------------------------------
+9 -2
View File
@@ -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()
{
+41 -1
View File
@@ -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;
}
}