tidy lab 04+05

This commit is contained in:
SowinskiBraeden committed 2025-10-27 14:34:18 -07:00
1 parent e9d574c651
commit 8beed930f4
10 files changed
+129 -14

No files matched your search

+3 -1
View File
@@ -10,7 +10,9 @@ package ca.bcit.comp2522.lab04;
* @author Calvin Arifianto * @author Calvin Arifianto
* @version 1.0.0 * @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; private static final int MAX_GENRE_LENGTH = 30;
@@ -10,7 +10,9 @@ package ca.bcit.comp2522.lab04;
* @author Calvin Arifianto * @author Calvin Arifianto
* @version 1.0.0 * @version 1.0.0
*/ */
public class Autobiography extends Biography implements Printable public class Autobiography
extends Biography
implements Printable
{ {
/** /**
* Autobiography constructor * Autobiography constructor
@@ -9,8 +9,11 @@ package ca.bcit.comp2522.lab04;
* @author Calvin Arifianto * @author Calvin Arifianto
* @version 1.0.0 * @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; private final Person subject;
/** /**
@@ -62,7 +65,7 @@ public class Biography extends Book implements Printable
{ {
if (subject == null) if (subject == null)
{ {
return 0; return DEFAULT_HASH_CODE;
} }
return subject.hashCode(); return subject.hashCode();
} }
@@ -89,6 +92,10 @@ public class Biography extends Book implements Printable
System.out.println(builder.toString()); System.out.println(builder.toString());
} }
/**
* getSubject of the Biography i.e. the Person it is about
* @return subject of biography
*/
public Person getSubject() { public Person getSubject() {
return this.subject; return this.subject;
} }
+7 -4
View File
@@ -14,7 +14,10 @@ public class Book
Printable, Printable,
Reversible 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 MIN_YEAR = 1;
private static final int MAX_YEAR = 2025; private static final int MAX_YEAR = 2025;
@@ -87,11 +90,11 @@ public class Book
public int compareTo(final Book other) public int compareTo(final Book other)
{ {
if (this.year < other.year) { if (this.year < other.year) {
return -1; return LESS_THAN;
} else if (this.year > other.year) { } else if (this.year > other.year) {
return 1; return GREATER_THAN;
} }
return 0; return EQUALS;
} }
} }
+2 -1
View File
@@ -10,7 +10,8 @@ package ca.bcit.comp2522.lab04;
* @author Calvin Arifianto * @author Calvin Arifianto
* @version 1.0.0 * @version 1.0.0
*/ */
public class Name implements Printable public class Name
implements Printable
{ {
private static final int MAX_NAME_CHARACTERS = 50; private static final int MAX_NAME_CHARACTERS = 50;
@@ -19,6 +19,8 @@ import java.util.Iterator;
*/ */
public class BookStore { public class BookStore {
private static final int DECADE_RANGE = 9; 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 String bookStoreName;
private final List<Novel> novels; private final List<Novel> novels;
@@ -226,7 +228,7 @@ public class BookStore {
String title; String title;
int longest; int longest;
longest = 0; longest = DEFAULT_LONGEST_VALUE;
title = ""; title = "";
for (final Novel novel : this.novels) { for (final Novel novel : this.novels) {
@@ -264,7 +266,7 @@ public class BookStore {
{ {
int count; int count;
count = 0; count = DEFAULT_LONGEST_VALUE;
for (final Novel novel : this.novels) { for (final Novel novel : this.novels) {
if (novel.getTitle().toLowerCase().contains(word.toLowerCase())) { if (novel.getTitle().toLowerCase().contains(word.toLowerCase())) {
@@ -289,7 +291,7 @@ public class BookStore {
) { ) {
int inRange; int inRange;
inRange = 0; inRange = DEFAULT_LONGEST_VALUE;
for (final Novel novel : this.novels) { for (final Novel novel : this.novels) {
if (novel.getYearPublished() >= first && novel.getYearPublished() <= last) { 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;
} }
/** /**
+3 -1
View File
@@ -8,7 +8,9 @@ package ca.bcit.comp2522.lab05;
* @author Nico Agostini * @author Nico Agostini
* @author Trishaan Shetty * @author Trishaan Shetty
*/ */
public class Novel implements Comparable<Novel> { public class Novel
implements Comparable<Novel>
{
private final String title; private final String title;
private final String authorName; private final String authorName;
private final int yearPublished; private final int yearPublished;
@@ -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;
}
}
@@ -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<HockeyPlayer> 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<HockeyPlayer> getRoster() {
return this.roster;
}
}
@@ -0,0 +1,7 @@
package ca.bcit.comp2522.lab06;
public class Main {
public static void main(final String[] args) {
}
}