diff --git a/book/src/main/java/ru/molokoin/Book.java b/book/src/main/java/ru/molokoin/Book.java index 7f80871..887a1b4 100644 --- a/book/src/main/java/ru/molokoin/Book.java +++ b/book/src/main/java/ru/molokoin/Book.java @@ -9,16 +9,33 @@ public class Book { Book(Object name, Object year, Object publisher){} Book(Object name, Object author, Object year, Object publisher){ this(name, year, publisher); - //TODO authorsUppend(author){не забыть создать новый массив, если его небыло} - String[] authors = new String[1]; - authors[0] = (String) author; - setAuthors(authors); + setAuthors(uppendAuthors((String)author)); } Book(Object name, Object[] authors, Object year, Object publisher){ this(name, year, publisher); String[] a = (String[]) authors; setAuthors(a); } + + public String[] uppendAuthors(String author){ + String[] result; + try { + if (getAuthors() == null)throw new NullPointerException("Перечень авторов пока пуст ..."); + } catch (NullPointerException e) { + e.printStackTrace(); + result = new String[1]; + result[0] = author; + return result; + } + result = new String[getAuthorsCount() + 1]; + int i = 0; + while (i < getAuthorsCount()){ + result[i] = getAuthorByIndex(i); + i++; + } + result[getAuthorsCount()] = author; + return result; + } public String getAuthorByIndex(int index){ String author = getAuthors()[index]; return author; diff --git a/book/target/classes/ru/molokoin/Book.class b/book/target/classes/ru/molokoin/Book.class index 238bccb..689b20b 100644 Binary files a/book/target/classes/ru/molokoin/Book.class and b/book/target/classes/ru/molokoin/Book.class differ