16 files changed
+706
-46
No files matched your search
Generated
-6
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Kotlin2JvmCompilerArguments">
|
||||
<option name="jvmTarget" value="1.8" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
-8
@@ -1,8 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="KotlinJavaRuntime" type="repository">
|
||||
<properties maven-id="org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.1.21" />
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
Generated
-12
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MaterialThemeProjectNewConfig">
|
||||
<option name="metadata">
|
||||
<MTProjectMetadataState>
|
||||
<option name="migrated" value="true" />
|
||||
<option name="pristineConfig" value="false" />
|
||||
<option name="userId" value="335bdae2:1992ba776c5:-7ffe" />
|
||||
</MTProjectMetadataState>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
Generated
-6
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_24" project-jdk-name="24" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
-8
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/comp2522.iml" filepath="$PROJECT_DIR$/comp2522.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
-6
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,398 @@
|
||||
package ca.bcit.comp2522.lab04;
|
||||
|
||||
//TODO proof read. Added the implementation and over rid the printable method.
|
||||
|
||||
/**
|
||||
* Date contains useful methods about a given date.
|
||||
*
|
||||
* @author Braeden Sowinski
|
||||
* @author Nico Agostini
|
||||
* @author Trishaan Shetty
|
||||
* @author Calvin Arifianto
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public final class Date implements Printable
|
||||
{
|
||||
|
||||
// Domain of dates
|
||||
private static final int MIN_YEAR = 1800;
|
||||
private static final int MAX_YEAR = 2025;
|
||||
private static final int MIN_DAY = 1;
|
||||
|
||||
// Constants for calculating leap year, and days in given month
|
||||
private static final int YEARS_BTWN_LEAP_YEARS = 4;
|
||||
private static final int YEARS_PER_CENTURY = 100;
|
||||
private static final int YEARS_BTWN_LEAP_CENTURIES = 400;
|
||||
private static final int LEAP_YEAR_MOD_RESULT = 0;
|
||||
private static final int LEAP_YEAR_DAYS = 29;
|
||||
private static final int NON_LEAP_YEAR_DAYS = 28;
|
||||
private static final int MONTH_MOST_DAYS = 31;
|
||||
private static final int MONTH_REGULAR_DAYS = 30;
|
||||
private static final int EVEN = 2;
|
||||
private static final int IS_DIVISIBLE = 1;
|
||||
|
||||
// Constants to get next or last value
|
||||
private static final int GET_NEXT = 1;
|
||||
private static final int GET_PREVIOUS = 1;
|
||||
|
||||
// Constants to add to sum for calculating day of week
|
||||
private static final int CENTURY_CODE_YEAR_EIGHTEEN_HUNDREDS = 2;
|
||||
private static final int CENTURY_CODE_YEAR_TWO_THOUSANDS = 6;
|
||||
private static final int CENTURY_CODE_AND_MONTH_CODE = 12;
|
||||
|
||||
// Century definitions
|
||||
private static final int YEAR_EIGHTEEN_HUNDREDS = 1800;
|
||||
private static final int YEAR_NINETEEN_HUNDREDS = 1900;
|
||||
private static final int YEAR_TWO_THOUSANDS = 2000;
|
||||
|
||||
// Months
|
||||
private static final int JANUARY = 1;
|
||||
private static final int FEBRUARY = 2;
|
||||
private static final int MARCH = 3;
|
||||
private static final int APRIL = 4;
|
||||
private static final int MAY = 5;
|
||||
private static final int JUNE = 6;
|
||||
private static final int JULY = 7;
|
||||
private static final int AUGUST = 8;
|
||||
private static final int SEPTEMBER = 9;
|
||||
private static final int OCTOBER = 10;
|
||||
private static final int NOVEMBER = 11;
|
||||
private static final int DECEMBER = 12;
|
||||
|
||||
// Days of week
|
||||
private static final int SATURDAY = 0;
|
||||
private static final int SUNDAY = 1;
|
||||
private static final int MONDAY = 2;
|
||||
private static final int TUESDAY = 3;
|
||||
private static final int WEDNESDAY = 4;
|
||||
private static final int THURSDAY = 5;
|
||||
private static final int FRIDAY = 6;
|
||||
|
||||
// Constants used to calculate day of week
|
||||
private static final int DIVISION_BY_TWELVE = 12;
|
||||
private static final int DIVISION_BY_FOUR = 4;
|
||||
private static final int DAYS_OF_WEEK = 7;
|
||||
private static final String MONTH_CODES = "144025036146";
|
||||
|
||||
private final int year;
|
||||
private final int month;
|
||||
private final int day;
|
||||
|
||||
/*
|
||||
isLeapYear calculates if a given year is a leap year or not.
|
||||
|
||||
a) A year is a leap year if it is divisible by LEAP_YEAR_MOD_FOUR,
|
||||
|
||||
b) If the year is also divisible by LEAP_YEAR_MOD_ONE_HUNDRED then
|
||||
it is not a leap year.
|
||||
|
||||
c) If the year is divisible by LEAP_YEAR_MOD_ONE_HUNDRED and is
|
||||
divisible by LEAP_YEAR_MOD_FOUR_HUNDRED, then it is a leap year.
|
||||
*/
|
||||
private static boolean isLeapYear(final int year)
|
||||
{
|
||||
|
||||
final boolean isLeapYear;
|
||||
final boolean leapYearRuleOne;
|
||||
final boolean leapYearRuleTwo;
|
||||
|
||||
leapYearRuleOne = (year % YEARS_BTWN_LEAP_CENTURIES) == LEAP_YEAR_MOD_RESULT;
|
||||
leapYearRuleTwo = (year % YEARS_BTWN_LEAP_YEARS == LEAP_YEAR_MOD_RESULT && year % YEARS_PER_CENTURY != LEAP_YEAR_MOD_RESULT);
|
||||
|
||||
isLeapYear = leapYearRuleOne || leapYearRuleTwo;
|
||||
|
||||
return isLeapYear;
|
||||
}
|
||||
|
||||
/**
|
||||
daysInMonth calculates the max number of days in a given month.
|
||||
|
||||
If the month is February, we must know if it is a leap year or
|
||||
not, as the numbers of days changes.
|
||||
|
||||
Otherwise, for any other month, we determine if the month comes
|
||||
before August, as every odd month from January to July, has
|
||||
MONTH_MOST_DAYS, and every even month has MONTH_REGULAR_DAYS.
|
||||
|
||||
If the month is after August, then from August to December every
|
||||
odd month hsa MONTH_MOST_DAYS, and every even month has
|
||||
MONTH_REGULAR_DAYS.
|
||||
*/
|
||||
private static int daysInMonth(
|
||||
final int month,
|
||||
final boolean isLeapYear
|
||||
) {
|
||||
|
||||
if (month == FEBRUARY)
|
||||
{
|
||||
if (isLeapYear) {
|
||||
return LEAP_YEAR_DAYS;
|
||||
} else {
|
||||
return NON_LEAP_YEAR_DAYS;
|
||||
}
|
||||
}
|
||||
|
||||
final boolean longMonth;
|
||||
|
||||
if (month <= JULY) {
|
||||
longMonth = (month % EVEN) == IS_DIVISIBLE;
|
||||
} else {
|
||||
longMonth = ((month + GET_NEXT) % EVEN) == IS_DIVISIBLE;
|
||||
}
|
||||
|
||||
if (longMonth) {
|
||||
return MONTH_MOST_DAYS;
|
||||
} else {
|
||||
return MONTH_REGULAR_DAYS;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
validateYear checks input year is in valid range
|
||||
*/
|
||||
public static void validateYear(final int year)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
|
||||
if (year < MIN_YEAR || year > MAX_YEAR) {
|
||||
throw new IllegalArgumentException("invalid year");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
validateMonth checks input month is in valid range
|
||||
*/
|
||||
public static void validateMonth(final int month)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
|
||||
if (month < JANUARY || month > DECEMBER) {
|
||||
throw new IllegalArgumentException("invalid month");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
validateDay ensures the day given is less than the max day
|
||||
calculated by daysInMonth and greater than the MIN_DAY
|
||||
*/
|
||||
public static void validateDay(
|
||||
final int day,
|
||||
final int month,
|
||||
final int year
|
||||
)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
|
||||
final boolean leapYear;
|
||||
final int maxDays;
|
||||
|
||||
leapYear = isLeapYear(year);
|
||||
maxDays = daysInMonth(month, leapYear);
|
||||
|
||||
if (day < MIN_DAY || day > maxDays) {
|
||||
throw new IllegalArgumentException("invalid day");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Date constructor
|
||||
* @param year int
|
||||
* @param month int
|
||||
* @param day int
|
||||
*/
|
||||
public Date(
|
||||
final int year,
|
||||
final int month,
|
||||
final int day
|
||||
) {
|
||||
|
||||
validateYear(year);
|
||||
validateMonth(month);
|
||||
validateDay(day, month, year);
|
||||
|
||||
this.year = year;
|
||||
this.month = month;
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
/**
|
||||
* getYear of Date
|
||||
* @return year
|
||||
*/
|
||||
public final int getYear() {
|
||||
return this.year;
|
||||
}
|
||||
|
||||
/**
|
||||
* getMonth of Date
|
||||
* @return month
|
||||
*/
|
||||
public final String getMonth()
|
||||
{
|
||||
|
||||
final String month;
|
||||
|
||||
if (this.month == JANUARY) {
|
||||
month = "January";
|
||||
} else if (this.month == FEBRUARY) {
|
||||
month = "February";
|
||||
} else if (this.month == MARCH) {
|
||||
month = "March";
|
||||
} else if (this.month == APRIL) {
|
||||
month = "April";
|
||||
} else if (this.month == MAY) {
|
||||
month = "May";
|
||||
} else if (this.month == JUNE) {
|
||||
month = "June";
|
||||
} else if (this.month == JULY) {
|
||||
month = "July";
|
||||
} else if (this.month == AUGUST) {
|
||||
month = "August";
|
||||
} else if (this.month == SEPTEMBER) {
|
||||
month = "September";
|
||||
} else if (this.month == OCTOBER) {
|
||||
month = "October";
|
||||
} else if (this.month == NOVEMBER) {
|
||||
month = "November";
|
||||
} else if (this.month == DECEMBER) {
|
||||
month = "December";
|
||||
} else {
|
||||
throw new IllegalArgumentException("invalid month");
|
||||
}
|
||||
|
||||
return month;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDay of Date
|
||||
* @return day
|
||||
*/
|
||||
public final int getDay() {
|
||||
return this.day;
|
||||
}
|
||||
|
||||
/**
|
||||
* getYyyyMmDd formatted as string
|
||||
* @return date in YyyyMmDd format
|
||||
*/
|
||||
public final String getYyyyMmDd()
|
||||
{
|
||||
final String date;
|
||||
|
||||
date = this.year + "-" + this.month + "-" + this.day;
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDayOfWeek
|
||||
*
|
||||
* To get the day of the week, do the following seven steps for dates in the 1900s:
|
||||
*
|
||||
* e.g. October 31 1977:
|
||||
* step 1: calculate the number of twelves in 77:
|
||||
* 6
|
||||
* step 2: calculate the remainder from step 1: 77 - 12*6 = 77 - 72 =
|
||||
* 5
|
||||
* step 3: calculate the number of fours in step 2: 5/4 = 1.25, so
|
||||
* 1
|
||||
* step 4: add the day of the month to each step above: 31 + 6 + 5 + 1 =
|
||||
* 43
|
||||
* step 5: add the month code (for jfmamjjasond: 144025036146): for october it is 1: 43 + 1 =
|
||||
* 44
|
||||
* step 6: add the previous five numbers: (44) and mod by 7: 44%7 = 2 (44/7 = 6 remainder 2)
|
||||
* step 7: sat sun mon tue wed thu fri is 0 1 2 3 4 5 6; our 2 means Oct 31 1977 was monday
|
||||
* Extra notes:
|
||||
* a) for January/February dates in leap years, add 6 at the start
|
||||
* b) for all dates in the 2000s, add 6 at the start
|
||||
* c) for all dates in the 1800s, add 2 at the star
|
||||
*
|
||||
* @return day of week
|
||||
*/
|
||||
public final String getDayOfWeek()
|
||||
{
|
||||
|
||||
final int year;
|
||||
final int century;
|
||||
final String monthCode;
|
||||
|
||||
final int step0;
|
||||
final int step1;
|
||||
final int step2;
|
||||
final int step3;
|
||||
final int step4;
|
||||
final int step5;
|
||||
|
||||
final int dayIndex;
|
||||
final String day;
|
||||
|
||||
monthCode = MONTH_CODES.charAt(this.month - GET_PREVIOUS) + "";
|
||||
|
||||
if (this.year < YEAR_NINETEEN_HUNDREDS) {
|
||||
century = YEAR_EIGHTEEN_HUNDREDS;
|
||||
} else if (this.year < YEAR_TWO_THOUSANDS) {
|
||||
century = YEAR_NINETEEN_HUNDREDS;
|
||||
} else {
|
||||
century = YEAR_TWO_THOUSANDS;
|
||||
}
|
||||
|
||||
year = this.year - century;
|
||||
|
||||
if (
|
||||
isLeapYear(this.year) &&
|
||||
(this.month == JANUARY || this.month == FEBRUARY) &&
|
||||
this.year >= YEAR_TWO_THOUSANDS
|
||||
) {
|
||||
|
||||
step0 = CENTURY_CODE_AND_MONTH_CODE;
|
||||
|
||||
} else if (
|
||||
isLeapYear(this.year) &&
|
||||
(this.month == JANUARY || this.month == FEBRUARY)
|
||||
) {
|
||||
step0 = CENTURY_CODE_YEAR_TWO_THOUSANDS;
|
||||
} else if (this.year >= YEAR_TWO_THOUSANDS) {
|
||||
step0 = CENTURY_CODE_YEAR_TWO_THOUSANDS;
|
||||
} else if (this.year < YEAR_NINETEEN_HUNDREDS) {
|
||||
step0 = CENTURY_CODE_YEAR_EIGHTEEN_HUNDREDS;
|
||||
} else {
|
||||
step0 = 0;
|
||||
}
|
||||
|
||||
step1 = year / DIVISION_BY_TWELVE;
|
||||
step2 = year - (DIVISION_BY_TWELVE * step1);
|
||||
step3 = step2 / DIVISION_BY_FOUR;
|
||||
step4 = this.day + step0 + step1 + step2 + step3;
|
||||
step5 = step4 + Integer.parseInt(monthCode);
|
||||
|
||||
dayIndex = step5 % DAYS_OF_WEEK;
|
||||
|
||||
if (dayIndex == SATURDAY) {
|
||||
day = "Saturday";
|
||||
} else if (dayIndex == SUNDAY) {
|
||||
day = "Sunday";
|
||||
} else if (dayIndex == MONDAY) {
|
||||
day = "Monday";
|
||||
} else if (dayIndex == TUESDAY) {
|
||||
day = "Tuesday";
|
||||
} else if (dayIndex == WEDNESDAY) {
|
||||
day = "Wednesday";
|
||||
} else if (dayIndex == THURSDAY) {
|
||||
day = "Thursday";
|
||||
} else if (dayIndex == FRIDAY) {
|
||||
day = "Friday";
|
||||
} else {
|
||||
throw new IllegalArgumentException("invalid day");
|
||||
}
|
||||
|
||||
return day;
|
||||
}
|
||||
|
||||
/**
|
||||
* display Date to console in yyyy-mm-dd format
|
||||
*/
|
||||
@Override
|
||||
public void display() {
|
||||
System.out.println(getYyyyMmDd());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package ca.bcit.comp2522.lab04;
|
||||
|
||||
/**
|
||||
* Name class holds first and last name,
|
||||
* and validates name lengths
|
||||
*
|
||||
* @author Braeden Sowinski
|
||||
* @author Nico Agostini
|
||||
* @author Trishaan Shetty
|
||||
* @author Calvin Arifianto
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class Name implements Printable
|
||||
{
|
||||
private final String first;
|
||||
private final String last;
|
||||
|
||||
private static final int MAX_NAME_CHARACTERS = 50;
|
||||
|
||||
/**
|
||||
* Name constructor
|
||||
* @param first name to save
|
||||
* @param last name to save
|
||||
*/
|
||||
public Name(final String first, final String last)
|
||||
{
|
||||
Validator.validateString(first, MAX_NAME_CHARACTERS);
|
||||
Validator.validateString(last, MAX_NAME_CHARACTERS);
|
||||
|
||||
this.first = first;
|
||||
this.last = last;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display()
|
||||
{
|
||||
System.out.println("First: " + first + " Last: " + last);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package ca.bcit.comp2522.lab04;
|
||||
|
||||
// TODO: implement Comparable, Printable, Reversible
|
||||
|
||||
/**
|
||||
* Person contains date of birth, death, and a name.
|
||||
*
|
||||
* @author Braeden Sowinski
|
||||
* @author Nico Agostini
|
||||
* @author Trishaan Shetty
|
||||
* @author Calvin Arifianto
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class Person
|
||||
{
|
||||
private final Date dateOfBirth;
|
||||
private final Date dateOfDeath;
|
||||
private final Name name;
|
||||
|
||||
/**
|
||||
* Person construct
|
||||
* @param dateOfBirth of person, cannot be null
|
||||
* @param dateOfDeath of person, can be null
|
||||
* @param name of person
|
||||
*/
|
||||
public Person(
|
||||
final Date dateOfBirth,
|
||||
final Date dateOfDeath,
|
||||
final Name name
|
||||
) {
|
||||
Validator.validateObject(dateOfBirth, "date of birth");
|
||||
Validator.validateObject(name, "name");
|
||||
|
||||
this.dateOfBirth = dateOfBirth;
|
||||
this.dateOfDeath = dateOfDeath;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package ca.bcit.comp2522.lab04;
|
||||
|
||||
/**
|
||||
* Printable classes must print all their instance
|
||||
* variables and the instance variables of their parents
|
||||
* to the console in a sentence.
|
||||
*
|
||||
* @author Braeden Sowinski
|
||||
* @author Nico Agostini
|
||||
* @author Trishaan Shetty
|
||||
* @author Calvin Arifianto
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public interface Printable
|
||||
{
|
||||
void display();
|
||||
}
|
||||
@@ -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