tidy lab 04+05
This commit is contained in:
10 files changed
+129
-14
No files matched your search
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<Novel> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,7 +8,9 @@ package ca.bcit.comp2522.lab05;
|
||||
* @author Nico Agostini
|
||||
* @author Trishaan Shetty
|
||||
*/
|
||||
public class Novel implements Comparable<Novel> {
|
||||
public class Novel
|
||||
implements Comparable<Novel>
|
||||
{
|
||||
private final String title;
|
||||
private final String authorName;
|
||||
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) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user