create remaining lab04 classes and interfaces
This commit is contained in:
9 files changed
+222
-62
No files matched your search
Generated
+1
-3
@@ -5,11 +5,8 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="4481728b-524b-48ee-9d70-e414a15f05bd" name="Changes" comment="">
|
<list default="true" id="4481728b-524b-48ee-9d70-e414a15f05bd" name="Changes" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab04/Date.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab04/Date.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab04/Name.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab04/Name.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab04/Name.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab04/Name.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab04/Person.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab04/Person.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab04/Person.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab04/Person.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab04/Printable.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab04/Printable.java" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -20,6 +17,7 @@
|
|||||||
<option name="RECENT_TEMPLATES">
|
<option name="RECENT_TEMPLATES">
|
||||||
<list>
|
<list>
|
||||||
<option value="Exception" />
|
<option value="Exception" />
|
||||||
|
<option value="Interface" />
|
||||||
<option value="Class" />
|
<option value="Class" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package ca.bcit.comp2522.lab04;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authors are just a Person but also
|
||||||
|
* have a genre in which they write.
|
||||||
|
*
|
||||||
|
* @author Braeden Sowinski
|
||||||
|
* @author Nico Agostini
|
||||||
|
* @author Trishaan Shetty
|
||||||
|
* @author Calvin Arifianto
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
public class Author extends Person {
|
||||||
|
private static final int MAX_GENRE_LENGTH = 30;
|
||||||
|
|
||||||
|
private final String genre;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author constructor
|
||||||
|
* @param name of the author
|
||||||
|
* @param dateOfBirth of the author
|
||||||
|
* @param dateOfDeath of author if they did die (can be null)
|
||||||
|
* @param genre that the author writes in
|
||||||
|
*/
|
||||||
|
public Author(
|
||||||
|
final Name name,
|
||||||
|
final Date dateOfBirth,
|
||||||
|
final Date dateOfDeath,
|
||||||
|
final String genre
|
||||||
|
) {
|
||||||
|
super(dateOfBirth, dateOfDeath, name);
|
||||||
|
|
||||||
|
Validator.validateString(genre, MAX_GENRE_LENGTH);
|
||||||
|
|
||||||
|
this.genre = genre;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package ca.bcit.comp2522.lab04;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Autobiography is just a Biography about the
|
||||||
|
* author and not another Person.
|
||||||
|
*
|
||||||
|
* @author Braeden Sowinski
|
||||||
|
* @author Nico Agostini
|
||||||
|
* @author Trishaan Shetty
|
||||||
|
* @author Calvin Arifianto
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
public class Autobiography extends Biography
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Autobiography constructor
|
||||||
|
* @param title of autobiography
|
||||||
|
* @param year published
|
||||||
|
* @param author and subject of autobiography
|
||||||
|
*/
|
||||||
|
public Autobiography(
|
||||||
|
final String title,
|
||||||
|
final int year,
|
||||||
|
final Author author
|
||||||
|
) {
|
||||||
|
super(title, year, author, author);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package ca.bcit.comp2522.lab04;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Biography is a Book about a Person
|
||||||
|
*
|
||||||
|
* @author Braeden Sowinski
|
||||||
|
* @author Nico Agostini
|
||||||
|
* @author Trishaan Shetty
|
||||||
|
* @author Calvin Arifianto
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
public class Biography extends Book
|
||||||
|
{
|
||||||
|
private final Person subject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Biography constructor
|
||||||
|
* @param title of Biography
|
||||||
|
* @param year published
|
||||||
|
* @param author of Biography
|
||||||
|
* @param subject that the Biography is about
|
||||||
|
*/
|
||||||
|
public Biography(
|
||||||
|
final String title,
|
||||||
|
final int year,
|
||||||
|
final Author author,
|
||||||
|
final Person subject
|
||||||
|
) {
|
||||||
|
super(title, year, author);
|
||||||
|
|
||||||
|
Validator.validateObject(subject, "subject");
|
||||||
|
|
||||||
|
this.subject = subject;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package ca.bcit.comp2522.lab04;
|
||||||
|
|
||||||
|
// TODO: Implement Comparable, Printable, Reversible
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Book has an Author, year, and title
|
||||||
|
*
|
||||||
|
* @author Braeden Sowinski
|
||||||
|
* @author Nico Agostini
|
||||||
|
* @author Trishaan Shetty
|
||||||
|
* @author Calvin Arifianto
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
public class Book
|
||||||
|
{
|
||||||
|
private static final int MAX_TITLE_LENGTH = 100;
|
||||||
|
private static final int MIN_YEAR = 1;
|
||||||
|
private static final int MAX_YEAR = 2025;
|
||||||
|
|
||||||
|
private final String title;
|
||||||
|
private final int year;
|
||||||
|
private final Author author;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Book constructor
|
||||||
|
* @param title of the book
|
||||||
|
* @param year the book was published
|
||||||
|
* @param author of the book
|
||||||
|
*/
|
||||||
|
public Book(
|
||||||
|
final String title,
|
||||||
|
final int year,
|
||||||
|
final Author author
|
||||||
|
) {
|
||||||
|
Validator.validateString(title, MAX_TITLE_LENGTH);
|
||||||
|
Validator.validateObject(author, "author");
|
||||||
|
Validator.validateInteger(year, MIN_YEAR, MAX_YEAR);
|
||||||
|
|
||||||
|
this.title = title;
|
||||||
|
this.year = year;
|
||||||
|
this.author = author;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,47 +15,7 @@ public class Name implements Printable
|
|||||||
private final String first;
|
private final String first;
|
||||||
private final String last;
|
private final String last;
|
||||||
|
|
||||||
private static final int MAX_CHARACTERS = 50;
|
private static final int MAX_NAME_CHARACTERS = 50;
|
||||||
|
|
||||||
/**
|
|
||||||
* stringValidator checks the string being passed into it for
|
|
||||||
* being null, blank, empty or over the limit of characters.
|
|
||||||
*
|
|
||||||
* @param stringToCheck passes the string to be checked.
|
|
||||||
* @param maxLength passes the integer value of the number of character count
|
|
||||||
* the String can be.
|
|
||||||
* */
|
|
||||||
private static void stringValidator(final String stringToCheck, final int maxLength)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (stringToCheck == null)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("String cannot be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stringToCheck.isEmpty() ||
|
|
||||||
stringToCheck.isBlank())
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("String cannot be empty or blank");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stringToCheck.length() > maxLength)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"String longer than " + maxLength +
|
|
||||||
" characters"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stringValidator with default MAX_CHARACTERS restriction
|
|
||||||
* @param stringToCheck passes the string to be checked
|
|
||||||
*/
|
|
||||||
private static void stringValidator(final String stringToCheck)
|
|
||||||
{
|
|
||||||
stringValidator(stringToCheck, MAX_CHARACTERS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name constructor
|
* Name constructor
|
||||||
@@ -64,8 +24,8 @@ public class Name implements Printable
|
|||||||
*/
|
*/
|
||||||
public Name(final String first, final String last)
|
public Name(final String first, final String last)
|
||||||
{
|
{
|
||||||
stringValidator(first);
|
Validator.validateString(first, MAX_NAME_CHARACTERS);
|
||||||
stringValidator(last);
|
Validator.validateString(last, MAX_NAME_CHARACTERS);
|
||||||
|
|
||||||
this.first = first;
|
this.first = first;
|
||||||
this.last = last;
|
this.last = last;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package ca.bcit.comp2522.lab04;
|
package ca.bcit.comp2522.lab04;
|
||||||
|
|
||||||
|
// TODO: implement Comparable, Printable, Reversible
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Person contains date of birth, death, and a name.
|
* Person contains date of birth, death, and a name.
|
||||||
*
|
*
|
||||||
@@ -15,20 +17,6 @@ public class Person
|
|||||||
private final Date dateOfDeath;
|
private final Date dateOfDeath;
|
||||||
private final Name name;
|
private final Name name;
|
||||||
|
|
||||||
/**
|
|
||||||
* validateObject ensures a given object is not null
|
|
||||||
* @param object to ensure is not null
|
|
||||||
* @param objectName variable name of object for log
|
|
||||||
*/
|
|
||||||
private static void validateObject(
|
|
||||||
final Object object,
|
|
||||||
final String objectName
|
|
||||||
) {
|
|
||||||
if (object == null) {
|
|
||||||
throw new IllegalArgumentException(objectName + " cannot be null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Person construct
|
* Person construct
|
||||||
* @param dateOfBirth of person, cannot be null
|
* @param dateOfBirth of person, cannot be null
|
||||||
@@ -40,8 +28,8 @@ public class Person
|
|||||||
final Date dateOfDeath,
|
final Date dateOfDeath,
|
||||||
final Name name
|
final Name name
|
||||||
) {
|
) {
|
||||||
validateObject(dateOfBirth, "date of birth");
|
Validator.validateObject(dateOfBirth, "date of birth");
|
||||||
validateObject(name, "name");
|
Validator.validateObject(name, "name");
|
||||||
|
|
||||||
this.dateOfBirth = dateOfBirth;
|
this.dateOfBirth = dateOfBirth;
|
||||||
this.dateOfDeath = dateOfDeath;
|
this.dateOfDeath = dateOfDeath;
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package ca.bcit.comp2522.lab04;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reversible classes must print their name/title
|
||||||
|
* backwards.
|
||||||
|
*/
|
||||||
|
public interface Reversible {
|
||||||
|
void backward();
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package ca.bcit.comp2522.lab04;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator provides useful validation methods
|
||||||
|
* that many classes can use.
|
||||||
|
*
|
||||||
|
* @author Braeden Sowinski
|
||||||
|
* @author Nico Agostini
|
||||||
|
* @author Trishaan Shetty
|
||||||
|
* @author Calvin Arifianto
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
public final class Validator
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* validateString ensures a string is not empty, blank,
|
||||||
|
* null or greater than maxLength
|
||||||
|
* @param string to validate
|
||||||
|
* @param maxLength that string can be
|
||||||
|
*/
|
||||||
|
public static void validateString(final String string, final int maxLength) {
|
||||||
|
if (string == null || string.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("string cannot be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.length() > maxLength) {
|
||||||
|
throw new IllegalArgumentException("string cannot be longer than " + maxLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* validateObject ensures a given object is not null
|
||||||
|
* @param object to ensure is not null
|
||||||
|
* @param objectName variable name of object for log
|
||||||
|
*/
|
||||||
|
public static void validateObject(
|
||||||
|
final Object object,
|
||||||
|
final String objectName
|
||||||
|
) {
|
||||||
|
if (object == null) {
|
||||||
|
throw new IllegalArgumentException(objectName + " cannot be null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* validateInteger ensures a given number is within
|
||||||
|
* the correct provided range
|
||||||
|
* @param number to validate
|
||||||
|
* @param min of range inclusive
|
||||||
|
* @param max of range inclusive
|
||||||
|
*/
|
||||||
|
public static void validateInteger(
|
||||||
|
final int number,
|
||||||
|
final int min,
|
||||||
|
final int max
|
||||||
|
) {
|
||||||
|
if (number < min || number > max) {
|
||||||
|
throw new IllegalArgumentException(number + " is out of range" + min + " to " + max);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user