clean lab04

This commit is contained in:
SowinskiBraeden committed 2025-10-03 20:07:10 -07:00
1 parent 9a3e662823
commit e5d7e36fdb
5 files changed
+156 -112

No files matched your search

+8 -9
View File
@@ -5,12 +5,11 @@
</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$/src/code/ca/bcit/comp2522/lab03/IDevice.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab03/IDevice.java" afterDir="false" /> <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/lab03/IPad.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab03/IPad.java" 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/lab03/IPhone.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab03/IPhone.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/lab03/IPhone16.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab03/IPhone16.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/lab03/IPod.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab03/IPod.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" />
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab03/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab03/Main.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" />
@@ -45,7 +44,7 @@
"ModuleVcsDetector.initialDetectionPerformed": "true", "ModuleVcsDetector.initialDetectionPerformed": "true",
"RunOnceActivity.ShowReadmeOnStart": "true", "RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true", "RunOnceActivity.git.unshallow": "true",
"git-widget-placeholder": "main", "git-widget-placeholder": "braeden/lab04",
"kotlin-language-version-configured": "true", "kotlin-language-version-configured": "true",
"last_opened_file_path": "/home/flami/Projects/comp2522", "last_opened_file_path": "/home/flami/Projects/comp2522",
"node.js.detected.package.eslint": "true", "node.js.detected.package.eslint": "true",
@@ -88,8 +87,8 @@
<component name="SharedIndexes"> <component name="SharedIndexes">
<attachedChunks> <attachedChunks>
<set> <set>
<option value="bundled-jdk-9823dce3aa75-bf35d07a577b-intellij.indexing.shared.core-IU-252.26199.169" /> <option value="bundled-jdk-9823dce3aa75-bf35d07a577b-intellij.indexing.shared.core-IU-252.26830.84" />
<option value="bundled-js-predefined-d6986cc7102b-9c94529fcfe0-JavaScript-IU-252.26199.169" /> <option value="bundled-js-predefined-d6986cc7102b-3aa1da707db6-JavaScript-IU-252.26830.84" />
</set> </set>
</attachedChunks> </attachedChunks>
</component> </component>
+54 -47
View File
@@ -11,66 +11,68 @@ package ca.bcit.comp2522.lab04;
* @author Calvin Arifianto * @author Calvin Arifianto
* @version 1.0.0 * @version 1.0.0
*/ */
public final class Date implements Printable { public final class Date implements Printable
{
// Domain of dates // Domain of dates
private static final int MIN_YEAR = 1800; private static final int MIN_YEAR = 1800;
private static final int MAX_YEAR = 2025; private static final int MAX_YEAR = 2025;
private static final int MIN_DAY = 1; private static final int MIN_DAY = 1;
// Constants for calculating leap year, and days in given month // Constants for calculating leap year, and days in given month
private static final int YEARS_BTWN_LEAP_YEARS = 4; private static final int YEARS_BTWN_LEAP_YEARS = 4;
private static final int YEARS_PER_CENTURY = 100; private static final int YEARS_PER_CENTURY = 100;
private static final int YEARS_BTWN_LEAP_CENTURIES = 400; private static final int YEARS_BTWN_LEAP_CENTURIES = 400;
private static final int LEAP_YEAR_MOD_RESULT = 0; private static final int LEAP_YEAR_MOD_RESULT = 0;
private static final int LEAP_YEAR_DAYS = 29; private static final int LEAP_YEAR_DAYS = 29;
private static final int NON_LEAP_YEAR_DAYS = 28; private static final int NON_LEAP_YEAR_DAYS = 28;
private static final int MONTH_MOST_DAYS = 31; private static final int MONTH_MOST_DAYS = 31;
private static final int MONTH_REGULAR_DAYS = 30; private static final int MONTH_REGULAR_DAYS = 30;
private static final int EVEN = 2; private static final int EVEN = 2;
private static final int IS_DIVISIBLE = 1; private static final int IS_DIVISIBLE = 1;
// Constants to get next or last value // Constants to get next or last value
private static final int GET_NEXT = 1; private static final int GET_NEXT = 1;
private static final int GET_PREVIOUS = 1; private static final int GET_PREVIOUS = 1;
// Constants to add to sum for calculating day of week // 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_EIGHTEEN_HUNDREDS = 2;
private static final int CENTURY_CODE_YEAR_TWO_THOUSANDS = 6; private static final int CENTURY_CODE_YEAR_TWO_THOUSANDS = 6;
private static final int CENTURY_CODE_AND_MONTH_CODE = 12; private static final int CENTURY_CODE_AND_MONTH_CODE = 12;
// Century definitions // Century definitions
private static final int YEAR_EIGHTEEN_HUNDREDS = 1800; private static final int YEAR_EIGHTEEN_HUNDREDS = 1800;
private static final int YEAR_NINETEEN_HUNDREDS = 1900; private static final int YEAR_NINETEEN_HUNDREDS = 1900;
private static final int YEAR_TWO_THOUSANDS = 2000; private static final int YEAR_TWO_THOUSANDS = 2000;
// Months // Months
private static final int JANUARY = 1; private static final int JANUARY = 1;
private static final int FEBRUARY = 2; private static final int FEBRUARY = 2;
private static final int MARCH = 3; private static final int MARCH = 3;
private static final int APRIL = 4; private static final int APRIL = 4;
private static final int MAY = 5; private static final int MAY = 5;
private static final int JUNE = 6; private static final int JUNE = 6;
private static final int JULY = 7; private static final int JULY = 7;
private static final int AUGUST = 8; private static final int AUGUST = 8;
private static final int SEPTEMBER = 9; private static final int SEPTEMBER = 9;
private static final int OCTOBER = 10; private static final int OCTOBER = 10;
private static final int NOVEMBER = 11; private static final int NOVEMBER = 11;
private static final int DECEMBER = 12; private static final int DECEMBER = 12;
// Days of week // Days of week
private static final int SATURDAY = 0; private static final int SATURDAY = 0;
private static final int SUNDAY = 1; private static final int SUNDAY = 1;
private static final int MONDAY = 2; private static final int MONDAY = 2;
private static final int TUESDAY = 3; private static final int TUESDAY = 3;
private static final int WEDNESDAY = 4; private static final int WEDNESDAY = 4;
private static final int THURSDAY = 5; private static final int THURSDAY = 5;
private static final int FRIDAY = 6; private static final int FRIDAY = 6;
// Constants used to calculate day of week // Constants used to calculate day of week
private static final int DIVISION_BY_TWELVE = 12; private static final int DIVISION_BY_TWELVE = 12;
private static final int DIVISION_BY_FOUR = 4; private static final int DIVISION_BY_FOUR = 4;
private static final int DAYS_OF_WEEK = 7; private static final int DAYS_OF_WEEK = 7;
private static final String MONTH_CODES = "144025036146"; private static final String MONTH_CODES = "144025036146";
private final int year; private final int year;
private final int month; private final int month;
@@ -87,7 +89,8 @@ public final class Date implements Printable {
c) If the year is divisible by LEAP_YEAR_MOD_ONE_HUNDRED and is 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. divisible by LEAP_YEAR_MOD_FOUR_HUNDRED, then it is a leap year.
*/ */
private static boolean isLeapYear(final int year) { private static boolean isLeapYear(final int year)
{
final boolean isLeapYear; final boolean isLeapYear;
final boolean leapYearRuleOne; final boolean leapYearRuleOne;
@@ -120,7 +123,8 @@ public final class Date implements Printable {
final boolean isLeapYear final boolean isLeapYear
) { ) {
if (month == FEBRUARY) { if (month == FEBRUARY)
{
if (isLeapYear) { if (isLeapYear) {
return LEAP_YEAR_DAYS; return LEAP_YEAR_DAYS;
} else { } else {
@@ -216,7 +220,6 @@ public final class Date implements Printable {
* @return year * @return year
*/ */
public final int getYear() { public final int getYear() {
return this.year; return this.year;
} }
@@ -224,7 +227,8 @@ public final class Date implements Printable {
* getMonth of Date * getMonth of Date
* @return month * @return month
*/ */
public final String getMonth() { public final String getMonth()
{
final String month; final String month;
@@ -264,7 +268,6 @@ public final class Date implements Printable {
* @return day * @return day
*/ */
public final int getDay() { public final int getDay() {
return this.day; return this.day;
} }
@@ -272,8 +275,8 @@ public final class Date implements Printable {
* getYyyyMmDd formatted as string * getYyyyMmDd formatted as string
* @return date in YyyyMmDd format * @return date in YyyyMmDd format
*/ */
public final String getYyyyMmDd() { public final String getYyyyMmDd()
{
final String date; final String date;
date = this.year + "-" + this.month + "-" + this.day; date = this.year + "-" + this.month + "-" + this.day;
@@ -306,7 +309,8 @@ public final class Date implements Printable {
* *
* @return day of week * @return day of week
*/ */
public final String getDayOfWeek() { public final String getDayOfWeek()
{
final int year; final int year;
final int century; final int century;
@@ -335,16 +339,16 @@ public final class Date implements Printable {
year = this.year - century; year = this.year - century;
if ( if (
isLeapYear(this.year) && isLeapYear(this.year) &&
(this.month == JANUARY || this.month == FEBRUARY) && (this.month == JANUARY || this.month == FEBRUARY) &&
this.year >= YEAR_TWO_THOUSANDS this.year >= YEAR_TWO_THOUSANDS
) { ) {
step0 = CENTURY_CODE_AND_MONTH_CODE; step0 = CENTURY_CODE_AND_MONTH_CODE;
} else if ( } else if (
isLeapYear(this.year) && isLeapYear(this.year) &&
(this.month == JANUARY || this.month == FEBRUARY) (this.month == JANUARY || this.month == FEBRUARY)
) { ) {
step0 = CENTURY_CODE_YEAR_TWO_THOUSANDS; step0 = CENTURY_CODE_YEAR_TWO_THOUSANDS;
} else if (this.year >= YEAR_TWO_THOUSANDS) { } else if (this.year >= YEAR_TWO_THOUSANDS) {
@@ -384,6 +388,9 @@ public final class Date implements Printable {
return day; return day;
} }
/**
* display Date to console in yyyy-mm-dd format
*/
@Override @Override
public void display() { public void display() {
System.out.println(getYyyyMmDd()); System.out.println(getYyyyMmDd());
+44 -31
View File
@@ -1,20 +1,22 @@
package ca.bcit.comp2522.lab04; package ca.bcit.comp2522.lab04;
public class Name { /**
* 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 first;
private final String last; private final String last;
private static final int MAX_CHARACTERS = 50; private static final int MAX_CHARACTERS = 50;
public Name(final String first, final String last)
{
stringValidator(first, MAX_CHARACTERS);
stringValidator(last, MAX_CHARACTERS);
this.first = first;
this.last = last;
}
/** /**
* stringValidator checks the string being passed into it for * stringValidator checks the string being passed into it for
* being null, blank, empty or over the limit of characters. * being null, blank, empty or over the limit of characters.
@@ -23,44 +25,55 @@ public class Name {
* @param maxLength passes the integer value of the number of character count * @param maxLength passes the integer value of the number of character count
* the String can be. * the String can be.
* */ * */
public void stringValidator(final String stringToCheck, private static void stringValidator(final String stringToCheck, final int maxLength)
final int maxLength){ {
if (stringToCheck == null) if (stringToCheck == null)
{ {
throw new IllegalArgumentException( throw new IllegalArgumentException("String cannot be null");
"String cannot be null");
} }
if (stringToCheck.isBlank() || if (stringToCheck.isEmpty() ||
stringToCheck.isEmpty()) stringToCheck.isBlank())
{ {
throw new IllegalArgumentException( throw new IllegalArgumentException("String cannot be empty or blank");
"String cannot be empty or blank");
} }
if (stringToCheck.length() > maxLength) if (stringToCheck.length() > maxLength)
{ {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"String longer than " + maxLength + "String longer than " + maxLength +
" characters"); " characters"
);
} }
} }
public void stringValidator(final String stringToCheck) /**
* 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);
}
if (stringToCheck == null) /**
{ * Name constructor
throw new IllegalArgumentException( * @param first name to save
"String cannot be null"); * @param last name to save
} */
public Name(final String first, final String last)
{
stringValidator(first);
stringValidator(last);
if (stringToCheck.isBlank() || this.first = first;
stringToCheck.isEmpty()) this.last = last;
{ }
throw new IllegalArgumentException(
"String cannot be empty or blank"); @Override
} public void display()
{
System.out.println("First: " + first + " Last: " + last);
} }
} }
+37 -24
View File
@@ -1,37 +1,50 @@
package ca.bcit.comp2522.lab04; package ca.bcit.comp2522.lab04;
public class Person { /**
* 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 dateOfBirth;
private final Date dateOfDeath; private final Date dateOfDeath;
private final Name name; private final Name name;
private final boolean CAN_BE_NULL = true; /**
private final boolean CANT_BE_NULL = false; * 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");
}
}
public Person(final Date dateOfBirth, /**
final Date dateOfDeath, * Person construct
final Name name) * @param dateOfBirth of person, cannot be null
{ * @param dateOfDeath of person, can be null
dateValidator(dateOfBirth, CAN_BE_NULL); * @param name of person
dateValidator(dateOfDeath, CANT_BE_NULL); */
public Person(
final Date dateOfBirth,
final Date dateOfDeath,
final Name name
) {
validateObject(dateOfBirth, "date of birth");
validateObject(name, "name");
this.dateOfBirth = dateOfBirth; this.dateOfBirth = dateOfBirth;
this.dateOfDeath = dateOfDeath; this.dateOfDeath = dateOfDeath;
this.name = name; this.name = name;
} }
public void dateValidator(final Date dateToBeChecked,
final boolean canBeNull)
{
if (!canBeNull)
{
if ( dateToBeChecked == null)
{
throw new IllegalArgumentException("Date cannot be null");
}
}
}
} }
+13 -1
View File
@@ -1,5 +1,17 @@
package ca.bcit.comp2522.lab04; package ca.bcit.comp2522.lab04;
public interface Printable { /**
* 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(); void display();
} }