clean lab04
This commit is contained in:
5 files changed
+115
-71
No files matched your search
Generated
+8
-9
@@ -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>
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ 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;
|
||||||
@@ -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;
|
||||||
@@ -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());
|
||||||
|
|||||||
@@ -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)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"String cannot be null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stringToCheck.isBlank() ||
|
/**
|
||||||
stringToCheck.isEmpty())
|
* Name constructor
|
||||||
|
* @param first name to save
|
||||||
|
* @param last name to save
|
||||||
|
*/
|
||||||
|
public Name(final String first, final String last)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException(
|
stringValidator(first);
|
||||||
"String cannot be empty or blank");
|
stringValidator(last);
|
||||||
|
|
||||||
|
this.first = first;
|
||||||
|
this.last = last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void display()
|
||||||
|
{
|
||||||
|
System.out.println("First: " + first + " Last: " + last);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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,
|
/**
|
||||||
|
* 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 Date dateOfDeath,
|
||||||
final Name name)
|
final Name name
|
||||||
{
|
) {
|
||||||
dateValidator(dateOfBirth, CAN_BE_NULL);
|
validateObject(dateOfBirth, "date of birth");
|
||||||
dateValidator(dateOfDeath, CANT_BE_NULL);
|
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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user