diff --git a/src/code/ca/bcit/comp2522/lab04/Author.java b/src/code/ca/bcit/comp2522/lab04/Author.java index 530e19d..3239806 100644 --- a/src/code/ca/bcit/comp2522/lab04/Author.java +++ b/src/code/ca/bcit/comp2522/lab04/Author.java @@ -10,7 +10,9 @@ package ca.bcit.comp2522.lab04; * @author Calvin Arifianto * @version 1.0.0 */ -public class Author extends Person implements Printable +public class Author + extends Person + implements Printable { private static final int MAX_GENRE_LENGTH = 30; diff --git a/src/code/ca/bcit/comp2522/lab04/Autobiography.java b/src/code/ca/bcit/comp2522/lab04/Autobiography.java index d28bf1f..f4638b9 100644 --- a/src/code/ca/bcit/comp2522/lab04/Autobiography.java +++ b/src/code/ca/bcit/comp2522/lab04/Autobiography.java @@ -10,7 +10,9 @@ package ca.bcit.comp2522.lab04; * @author Calvin Arifianto * @version 1.0.0 */ -public class Autobiography extends Biography implements Printable +public class Autobiography + extends Biography + implements Printable { /** * Autobiography constructor diff --git a/src/code/ca/bcit/comp2522/lab04/Biography.java b/src/code/ca/bcit/comp2522/lab04/Biography.java index b172dc1..fba19ec 100644 --- a/src/code/ca/bcit/comp2522/lab04/Biography.java +++ b/src/code/ca/bcit/comp2522/lab04/Biography.java @@ -9,8 +9,11 @@ package ca.bcit.comp2522.lab04; * @author Calvin Arifianto * @version 1.0.0 */ -public class Biography extends Book implements Printable +public class Biography + extends Book + implements Printable { + private static final int DEFAULT_HASH_CODE = 0; private final Person subject; /** @@ -62,7 +65,7 @@ public class Biography extends Book implements Printable { if (subject == null) { - return 0; + return DEFAULT_HASH_CODE; } return subject.hashCode(); } @@ -89,6 +92,10 @@ public class Biography extends Book implements Printable System.out.println(builder.toString()); } + /** + * getSubject of the Biography i.e. the Person it is about + * @return subject of biography + */ public Person getSubject() { return this.subject; } diff --git a/src/code/ca/bcit/comp2522/lab04/Book.java b/src/code/ca/bcit/comp2522/lab04/Book.java index 95040ea..6556934 100644 --- a/src/code/ca/bcit/comp2522/lab04/Book.java +++ b/src/code/ca/bcit/comp2522/lab04/Book.java @@ -14,7 +14,10 @@ public class Book Printable, Reversible { - private static final int MAX_TITLE_LENGTH = 100; + private static final int LESS_THAN = -1; + private static final int GREATER_THAN = 1; + private static final int EQUALS = 0; + private static final int MAX_TITLE_LENGTH = 1000; private static final int MIN_YEAR = 1; private static final int MAX_YEAR = 2025; @@ -87,11 +90,11 @@ public class Book public int compareTo(final Book other) { if (this.year < other.year) { - return -1; + return LESS_THAN; } else if (this.year > other.year) { - return 1; + return GREATER_THAN; } - return 0; + return EQUALS; } } diff --git a/src/code/ca/bcit/comp2522/lab04/Name.java b/src/code/ca/bcit/comp2522/lab04/Name.java index 9665136..39c4ed6 100644 --- a/src/code/ca/bcit/comp2522/lab04/Name.java +++ b/src/code/ca/bcit/comp2522/lab04/Name.java @@ -10,7 +10,8 @@ package ca.bcit.comp2522.lab04; * @author Calvin Arifianto * @version 1.0.0 */ -public class Name implements Printable +public class Name + implements Printable { private static final int MAX_NAME_CHARACTERS = 50; diff --git a/src/code/ca/bcit/comp2522/lab05/BookStore.java b/src/code/ca/bcit/comp2522/lab05/BookStore.java index f759333..fa786be 100644 --- a/src/code/ca/bcit/comp2522/lab05/BookStore.java +++ b/src/code/ca/bcit/comp2522/lab05/BookStore.java @@ -19,6 +19,8 @@ import java.util.Iterator; */ public class BookStore { private static final int DECADE_RANGE = 9; + private static final int DEFAULT_LONGEST_VALUE = 0; + private static final int TO_PERCENTAGE = 100; private final String bookStoreName; private final List novels; @@ -226,7 +228,7 @@ public class BookStore { String title; int longest; - longest = 0; + longest = DEFAULT_LONGEST_VALUE; title = ""; for (final Novel novel : this.novels) { @@ -264,7 +266,7 @@ public class BookStore { { int count; - count = 0; + count = DEFAULT_LONGEST_VALUE; for (final Novel novel : this.novels) { if (novel.getTitle().toLowerCase().contains(word.toLowerCase())) { @@ -289,7 +291,7 @@ public class BookStore { ) { int inRange; - inRange = 0; + inRange = DEFAULT_LONGEST_VALUE; for (final Novel novel : this.novels) { if (novel.getYearPublished() >= first && novel.getYearPublished() <= last) { @@ -297,7 +299,7 @@ public class BookStore { } } - return ((float) inRange / (float) this.novels.size()) * 100; + return ((float) inRange / (float) this.novels.size()) * TO_PERCENTAGE; } /** diff --git a/src/code/ca/bcit/comp2522/lab05/Novel.java b/src/code/ca/bcit/comp2522/lab05/Novel.java index a2b4c7b..e6a2577 100644 --- a/src/code/ca/bcit/comp2522/lab05/Novel.java +++ b/src/code/ca/bcit/comp2522/lab05/Novel.java @@ -8,7 +8,9 @@ package ca.bcit.comp2522.lab05; * @author Nico Agostini * @author Trishaan Shetty */ -public class Novel implements Comparable { +public class Novel + implements Comparable +{ private final String title; private final String authorName; private final int yearPublished; diff --git a/src/code/ca/bcit/comp2522/lab06/HockeyPlayer.java b/src/code/ca/bcit/comp2522/lab06/HockeyPlayer.java new file mode 100644 index 0000000..6bc2fd0 --- /dev/null +++ b/src/code/ca/bcit/comp2522/lab06/HockeyPlayer.java @@ -0,0 +1,57 @@ +package ca.bcit.comp2522.lab06; + +/** + * HockeyPlayer holds information of a + * hockey player and their simple stats. + * + * @author Braeden Sowinski + * @author Nico Agostini + * @author Trishaan Shetty + * @version 1.0.0 + */ +public class HockeyPlayer { + private static char FORWARD = 'F'; + private static char DEFENCE = 'D'; + private static char GOALIE = 'G'; + + private final String name; + private final char position; + private final int yearOfBirth; + private final int goals; + + private static void validateString(final String str) + throws IllegalArgumentException + { + if (str == null || str.isEmpty()) { + throw new IllegalArgumentException("invalid string"); + } + } + + private static void validatePosition(final char pos) + throws IllegalArgumentException + { + final char posUpper = Character.toUpperCase(pos); + + if (posUpper != FORWARD && + posUpper != DEFENCE && + posUpper != GOALIE + ) { + throw new IllegalArgumentException("invalid position"); + } + } + + public HockeyPlayer( + final String name, + final char position, + final int yearOfBirth, + final int goals + ) { + validateString(name); + validatePosition(position); + + this.name = name; + this.position = position; + this.yearOfBirth = yearOfBirth; + this.goals = goals; + } +} diff --git a/src/code/ca/bcit/comp2522/lab06/HockeyTeam.java b/src/code/ca/bcit/comp2522/lab06/HockeyTeam.java new file mode 100644 index 0000000..c4d79e7 --- /dev/null +++ b/src/code/ca/bcit/comp2522/lab06/HockeyTeam.java @@ -0,0 +1,32 @@ +package ca.bcit.comp2522.lab06; + +import java.util.ArrayList; +import java.util.List; + +public class HockeyTeam { + private final String name; + private final List roster; + + private static void validateString(final String str) + throws IllegalArgumentException + { + if (str == null || str.isEmpty()) { + throw new IllegalArgumentException("invalid string"); + } + } + + public HockeyTeam(final String name) { + validateString(name); + + this.name = name; + this.roster = new ArrayList<>(); + } + + public String getName() { + return this.name; + } + + public List getRoster() { + return this.roster; + } +} diff --git a/src/code/ca/bcit/comp2522/lab06/Main.java b/src/code/ca/bcit/comp2522/lab06/Main.java new file mode 100644 index 0000000..5e1b2cf --- /dev/null +++ b/src/code/ca/bcit/comp2522/lab06/Main.java @@ -0,0 +1,7 @@ +package ca.bcit.comp2522.lab06; + +public class Main { + public static void main(final String[] args) { + + } +} \ No newline at end of file