Conversation
| this.authorNameTwo = authorNameTwo; | ||
| this.authorNameThree = authorNameThree; | ||
| this.authorSurname = authorSurname; | ||
| this.authorFullName = authorName + " " + authorNameTwo + " " + authorNameThree + " " + authorSurname + " "; |
There was a problem hiding this comment.
В таком случае нужно проверять, что все имена указаны.
Так как если одно из них будет null, в твоем fullName появится Ivanov null Ivanovich
There was a problem hiding this comment.
У меня дальше идет замена null на "" и печатается все отлично.
There was a problem hiding this comment.
А зачем нам нужно увеличивать длину строки с fullName?
| private String authorName; | ||
| private String authorNameTwo; | ||
| private String authorNameThree; | ||
| private String authorSurname; | ||
| private String authorFullName; |
| Author author; | ||
| String nameOfBook; | ||
| int dateOfPublish; |
| Author author; | ||
| String nameOfBook; |
| Author author; | ||
| String nameOfBook; | ||
| int dateOfPublish; |
| for (int i = 0; i < books.length; i++) { | ||
| books[i] = null; | ||
| } |
There was a problem hiding this comment.
Этот цикл лишний.
Книги и так при инициализации заполнены нуллами.
| } | ||
| } | ||
|
|
||
| public void AddNewBook(Book book) { |
There was a problem hiding this comment.
Методы должны быть с маленькой буквы.
| System.out.println("Libryary:"); | ||
| for (Book book : books) { | ||
| if (book != null) { | ||
| System.out.print(book.toString()); | ||
| System.out.println(); | ||
| } else { | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
Никакого System.out.println
Метод toString обязан вернуть строковое представление объекта.
В консоль он печатать не должен.
| @Override | ||
| public String toString() { | ||
| return "Libryary" + System.lineSeparator() + books[0] + System.lineSeparator() + books[1]; | ||
| } |
There was a problem hiding this comment.
Вот тут не получилось.
Если книг будет больше придется все менять
А если вставляю цикл Java не дает из цикла вставить в return то что я хочу
Подскажи пожалуйста правильное решение))
There was a problem hiding this comment.
Делаем стринг билдер, добавляем туда "Library:\n", а затем в цикле аппендим к билдеру книги.
| this.authorNameTwo = authorNameTwo; | ||
| this.authorNameThree = authorNameThree; | ||
| this.authorSurname = authorSurname; | ||
| this.authorFullName = authorName + " " + authorNameTwo + " " + authorNameThree + " " + authorSurname + " "; |
There was a problem hiding this comment.
А зачем нам нужно увеличивать длину строки с fullName?
|
|
||
| private final Author author; | ||
| private final String nameOfBook; | ||
| int dateOfPublish; |
| private final String authorName; | ||
| private String authorNameTwo; | ||
| private String authorNameThree; | ||
| private String authorSurname; |
There was a problem hiding this comment.
Странно, что имя финальное, а фамилия нет.
| @Override | ||
| public String toString() { | ||
| return "Libryary" + System.lineSeparator() + books[0] + System.lineSeparator() + books[1]; | ||
| } |
There was a problem hiding this comment.
Делаем стринг билдер, добавляем туда "Library:\n", а затем в цикле аппендим к билдеру книги.
| for (int i = 0; i < books.length; i++) { | ||
| if (books[i] == null) { | ||
| books[i] = book; | ||
| return; | ||
| } | ||
| } |
There was a problem hiding this comment.
Ничего не выводит, если книга не была добавлена.
No description provided.