tidy formatting in lab 05
This commit is contained in:
3 files changed
+81
-42
No files matched your search
@@ -32,9 +32,8 @@ public class BookStore
|
||||
* hash maps and iterators
|
||||
* @param bookStoreName - The bookStoreName to call bookstore
|
||||
*/
|
||||
public BookStore(
|
||||
final String bookStoreName
|
||||
) {
|
||||
public BookStore(final String bookStoreName)
|
||||
{
|
||||
Validator.validateString(bookStoreName);
|
||||
|
||||
this.bookStoreName = bookStoreName;
|
||||
@@ -148,7 +147,8 @@ public class BookStore
|
||||
|
||||
novelsMap = new HashMap<>();
|
||||
|
||||
for (final Novel novel : this.novels) {
|
||||
for (final Novel novel : this.novels)
|
||||
{
|
||||
novelsMap.put(novel.getTitle(), novel);
|
||||
}
|
||||
|
||||
@@ -160,14 +160,18 @@ public class BookStore
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
final String key = iter.next();
|
||||
if (key.toLowerCase().contains("the")) {
|
||||
final String key;
|
||||
key = iter.next();
|
||||
|
||||
if (key.toLowerCase().contains("the"))
|
||||
{
|
||||
novelsMap.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Sorted and cleaned novels:");
|
||||
for (final Novel novel : novelsMap.values()) {
|
||||
for (final Novel novel : novelsMap.values())
|
||||
{
|
||||
System.out.println(novel);
|
||||
}
|
||||
}
|
||||
@@ -177,7 +181,8 @@ public class BookStore
|
||||
*/
|
||||
public void printAllTitles()
|
||||
{
|
||||
for (final Novel novel : this.novels) {
|
||||
for (final Novel novel : this.novels)
|
||||
{
|
||||
System.out.println(novel.getTitle().toUpperCase());
|
||||
}
|
||||
}
|
||||
@@ -188,8 +193,10 @@ public class BookStore
|
||||
*/
|
||||
public void printBookTitle(final String title)
|
||||
{
|
||||
for (final Novel novel : this.novels) {
|
||||
if (novel.getTitle().toLowerCase().contains(title.toLowerCase())) {
|
||||
for (final Novel novel : this.novels)
|
||||
{
|
||||
if (novel.getTitle().toLowerCase().contains(title.toLowerCase()))
|
||||
{
|
||||
System.out.println(novel.getTitle());
|
||||
}
|
||||
}
|
||||
@@ -203,7 +210,8 @@ public class BookStore
|
||||
{
|
||||
Collections.sort(this.novels);
|
||||
|
||||
for (final Novel novel : this.novels) {
|
||||
for (final Novel novel : this.novels)
|
||||
{
|
||||
System.out.println(novel.getTitle());
|
||||
}
|
||||
}
|
||||
@@ -236,8 +244,10 @@ public class BookStore
|
||||
longest = DEFAULT_LONGEST_VALUE;
|
||||
title = "";
|
||||
|
||||
for (final Novel novel : this.novels) {
|
||||
if (novel.getTitle().length() > longest) {
|
||||
for (final Novel novel : this.novels)
|
||||
{
|
||||
if (novel.getTitle().length() > longest)
|
||||
{
|
||||
longest = novel.getTitle().length();
|
||||
title = novel.getTitle();
|
||||
}
|
||||
@@ -254,11 +264,14 @@ public class BookStore
|
||||
*/
|
||||
public boolean isThereABookWrittenIn(final int year)
|
||||
{
|
||||
for (final Novel novel : this.novels) {
|
||||
if (novel.getYearPublished() == year) {
|
||||
for (final Novel novel : this.novels)
|
||||
{
|
||||
if (novel.getYearPublished() == year)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -273,8 +286,12 @@ public class BookStore
|
||||
|
||||
count = DEFAULT_LONGEST_VALUE;
|
||||
|
||||
for (final Novel novel : this.novels) {
|
||||
if (novel.getTitle().toLowerCase().contains(word.toLowerCase())) {
|
||||
for (final Novel novel : this.novels)
|
||||
{
|
||||
if (novel.getTitle()
|
||||
.toLowerCase()
|
||||
.contains(word.toLowerCase()))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@@ -291,16 +308,18 @@ public class BookStore
|
||||
* @return the percent of books written between first year and last year
|
||||
*/
|
||||
public float whichPercentWrittenBetween(
|
||||
final int first,
|
||||
final int last
|
||||
final int first,
|
||||
final int last
|
||||
) {
|
||||
int inRange;
|
||||
|
||||
inRange = DEFAULT_LONGEST_VALUE;
|
||||
|
||||
for (final Novel novel : this.novels) {
|
||||
for (final Novel novel : this.novels)
|
||||
{
|
||||
if (novel.getYearPublished() >= first &&
|
||||
novel.getYearPublished() <= last) {
|
||||
novel.getYearPublished() <= last)
|
||||
{
|
||||
inRange++;
|
||||
}
|
||||
}
|
||||
@@ -318,11 +337,16 @@ public class BookStore
|
||||
|
||||
oldest = null;
|
||||
|
||||
for (final Novel novel : this.novels) {
|
||||
if (oldest == null) {
|
||||
for (final Novel novel : this.novels)
|
||||
{
|
||||
if (oldest == null)
|
||||
{
|
||||
oldest = novel;
|
||||
} else {
|
||||
if (novel.getYearPublished() < oldest.getYearPublished()) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (novel.getYearPublished() < oldest.getYearPublished())
|
||||
{
|
||||
oldest = novel;
|
||||
}
|
||||
}
|
||||
@@ -337,13 +361,16 @@ public class BookStore
|
||||
* @param titleLength - The title length to compare books to
|
||||
* @return list of books matching given title length
|
||||
*/
|
||||
public List<Novel> getBooksThisLength(final int titleLength) {
|
||||
public List<Novel> getBooksThisLength(final int titleLength)
|
||||
{
|
||||
final List<Novel> booksOfLength;
|
||||
|
||||
booksOfLength = new ArrayList<>();
|
||||
|
||||
for (final Novel novel : this.novels) {
|
||||
if (novel.getTitle().length() == titleLength) {
|
||||
for (final Novel novel : this.novels)
|
||||
{
|
||||
if (novel.getTitle().length() == titleLength)
|
||||
{
|
||||
booksOfLength.add(novel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ package ca.bcit.comp2522.lab05;
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class Novel
|
||||
implements Comparable<Novel>
|
||||
implements Comparable<Novel>
|
||||
{
|
||||
private final String title;
|
||||
private final String authorName;
|
||||
@@ -23,11 +23,10 @@ public class Novel
|
||||
* @param authorName - The authorName of the novel
|
||||
* @param yearPublished - The year published of the novel
|
||||
*/
|
||||
public Novel(
|
||||
final String title,
|
||||
final String authorName,
|
||||
final int yearPublished
|
||||
) {
|
||||
public Novel(final String title,
|
||||
final String authorName,
|
||||
final int yearPublished)
|
||||
{
|
||||
Validator.validateString(title);
|
||||
Validator.validateString(authorName);
|
||||
|
||||
@@ -40,19 +39,28 @@ public class Novel
|
||||
* getTitle of the novel
|
||||
* @return title of the novel
|
||||
*/
|
||||
public String getTitle() { return this.title; }
|
||||
public String getTitle()
|
||||
{
|
||||
return this.title;
|
||||
}
|
||||
|
||||
/**
|
||||
* getAuthorName of the novel
|
||||
* @return author name of the novel
|
||||
*/
|
||||
public String getAuthorName() { return this.authorName; }
|
||||
public String getAuthorName()
|
||||
{
|
||||
return this.authorName;
|
||||
}
|
||||
|
||||
/**
|
||||
* getYearPublished of the novel
|
||||
* @return novel year published
|
||||
*/
|
||||
public int getYearPublished() { return this.yearPublished; }
|
||||
public int getYearPublished()
|
||||
{
|
||||
return this.yearPublished;
|
||||
}
|
||||
|
||||
/**
|
||||
* compareTo to sort novels based on title
|
||||
@@ -60,7 +68,8 @@ public class Novel
|
||||
* @return number value of comparison, i.e. >1, 0, <1
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(final Novel novel) {
|
||||
public int compareTo(final Novel novel)
|
||||
{
|
||||
return this.title.compareTo(novel.getTitle());
|
||||
}
|
||||
|
||||
@@ -70,7 +79,8 @@ public class Novel
|
||||
* @return the string representation of novel attributes
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder builder;
|
||||
builder = new StringBuilder();
|
||||
|
||||
|
||||
@@ -9,16 +9,18 @@ package ca.bcit.comp2522.lab05;
|
||||
* @author Calvin Arifianto
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class Validator {
|
||||
public class Validator
|
||||
{
|
||||
/**
|
||||
* validateString ensures string input is not null or empty
|
||||
* @param str - The String to validate
|
||||
* @throws IllegalArgumentException if invalid string
|
||||
*/
|
||||
public static void validateString(final String str)
|
||||
throws IllegalArgumentException
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (str == null || str.isEmpty()) {
|
||||
if (str == null || str.isEmpty())
|
||||
{
|
||||
throw new IllegalArgumentException("String cannot be null or empty");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user