From 137a059760bebd9a3cee98a41deca71603352577 Mon Sep 17 00:00:00 2001 From: esoe Date: Sat, 15 Oct 2022 03:28:48 +0300 Subject: [PATCH] qq --- book/src/main/java/ru/molokoin/Book.java | 92 +++++++++++++++--- book/src/main/java/ru/molokoin/Publisher.java | 30 ++++-- book/target/classes/ru/molokoin/Book.class | Bin 2670 -> 5026 bytes .../classes/ru/molokoin/Publisher.class | Bin 2689 -> 3342 bytes 4 files changed, 101 insertions(+), 21 deletions(-) diff --git a/book/src/main/java/ru/molokoin/Book.java b/book/src/main/java/ru/molokoin/Book.java index a07a96b..8988d32 100644 --- a/book/src/main/java/ru/molokoin/Book.java +++ b/book/src/main/java/ru/molokoin/Book.java @@ -5,18 +5,56 @@ public class Book { private Publisher publisher; private int year; private String[] authors; + private Publisher[] publishers = Publisher.getDefaultArray(); + Book(){} - Book(Object name, Object year, Object publisher){} - Book(Object name, Object author, Object year, Object publisher){ + Book(String name, int year, Publisher publisher){} + Book(String name, String author, int year, Publisher publisher){ this(name, year, publisher); setAuthors(uppendAuthors((String)author)); } - Book(Object name, Object[] authors, Object year, Object publisher){ + Book(String name, String[] authors, int year, Publisher publisher){ this(name, year, publisher); String[] a = (String[]) authors; setAuthors(a); } - //добавляем список авторов + public static Book[] getDefaultArray(){ + Book[] books = new Book[2]; + + //book 1 + String name = "Computer Science: основы программирования на Java, ООП, алгоритмы и структуры данных"; + books[0] = new Book(); + books[0].setName(name); + books[0].uppendAuthors("Седжвик Роберт"); + books[0].uppendAuthors("Уэйн Кевин"); + books[0].setPublisher(Publisher.getPublisherByName(Publisher.getDefaultArray(), "Питер")); + books[0].setYear(2018); + + //book 2 + name = "Разработка требований к программному обеспечению. 3-е издание, дополненное"; + books[1] = new Book(); + books[1].setName(name); + books[1].uppendAuthors("Вигерс Карл"); + books[1].setPublisher(Publisher.getPublisherByName(Publisher.getDefaultArray(), "БХВ")); + books[1].setYear(2019); + + return books; + } + public void print(){ + System.out.println("-------------------------------"); + System.out.println(toString()); + System.out.println("Наименование книги (name) :: " + name); + getPublisher().print(); + System.out.println("Год издания (year) :: " + year); + System.out.println("Авторы:"); + int i = 0; + while (i < getAuthorsCount()){ + System.out.println((i + 1) + ". " + getAuthors()[i]); + i++; + } + System.out.println("-------------------------------"); + } + //TODO добавляем список авторов public String[] uppendAuthors(String author){ String[] result; try { @@ -25,15 +63,14 @@ public class Book { 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++; + } finally { + 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){ @@ -42,8 +79,15 @@ public class Book { } //количество авторов книги public int getAuthorsCount(){ - //TODO проверить наличие массива - null - return getAuthors().length; + int count = 0; + try { + if (getAuthors() == null) throw new NullPointerException("авторы еще не добавлены в список ..."); + } catch (NullPointerException e) { + count = 0; + } finally { + count = getAuthors().length; + } + return count; } /** * @param name the name to set @@ -95,7 +139,25 @@ public class Book { * @return the author */ public String[] getAuthors() { - return authors; + String[] result = new String[0]; + try { + if (authors == null) throw new NullPointerException("Авторы еще не заносились в список ..."); + } catch (NullPointerException e) { + // TODO: handle exception + e.printStackTrace(); + result = new String[0]; + } finally { + result = authors; + } + return result; + } + public static void main(String[] args) { + Book[] books = Book.getDefaultArray(); + int i = 0; + while (i < books.length){ + books[i].print(); + i++; + } } } diff --git a/book/src/main/java/ru/molokoin/Publisher.java b/book/src/main/java/ru/molokoin/Publisher.java index 3d1563d..23a0a3d 100644 --- a/book/src/main/java/ru/molokoin/Publisher.java +++ b/book/src/main/java/ru/molokoin/Publisher.java @@ -11,15 +11,11 @@ public class Publisher { setName(name); setSity(sity); } - //выводим в консоль данные Издательства - public void print(){ - System.out.println("Издательство: " + getName() + " ----> " + "город: " + getSity()); - } /** * Метод класса. Возвращает массив данных об издательствах по умолчанию * @return */ - public static Publisher[] getDefaults(){ + public static Publisher[] getDefaultArray(){ Publisher[] defaultPublishers = new Publisher[4]; defaultPublishers[0] = new Publisher("Проспект", "Москва"); defaultPublishers[1] = new Publisher("Питер", "Санкт-Петербург"); @@ -27,6 +23,10 @@ public class Publisher { defaultPublishers[3] = new Publisher("Диалектика", "Киев"); return defaultPublishers; } + //выводим в консоль данные Издательства + public void print(){ + System.out.println("Издательство: " + getName() + " ----> " + "город: " + getSity()); + } /** * @param name the name to set * DONE: имя издательства не олжно быть пустой ссылкой @@ -67,8 +67,26 @@ public class Publisher { public String getSity() { return sity; } + public static Publisher getPublisherByName(Publisher[] publishers, String name){ + Publisher publisher = new Publisher(); + boolean isAcsists = false; + int i = 0; + while (i < publishers.length){ + if (name.equals((String)publishers[i].getName())){ + publisher = publishers[i]; + isAcsists = true; + } + i++; + } + try { + if(!isAcsists) throw new Exception("Указанное наименование издательства не найдено в каталоге. Установлено наименование города по умолчанию {noname sity} ..."); + } catch (Exception e) { + publisher = new Publisher(name, null); + } + return publisher; + } public static void main(String[] args) { - Publisher[] publishers = Publisher.getDefaults(); + Publisher[] publishers = Publisher.getDefaultArray(); int i = 0; while (i < publishers.length){ publishers[i].print(); diff --git a/book/target/classes/ru/molokoin/Book.class b/book/target/classes/ru/molokoin/Book.class index 689b20bb895c26209b92cb1e475262073236919c..a71e01d9ebe1796be50bf238dfe82245a46075c6 100644 GIT binary patch literal 5026 zcmb7HYgbg)8Gbg*z<@`=Q80+nsYxmfH-knK@Cs@~5p6(}Xd4Hd!00eThZ%#ZHi#x_ zjR|Tr7i)|rslAvMFAPKkKe|>woms2DpzYUw%jc%gyU$^`4X#v{v-dgs-S72zpS{oD z|NCeRz{|Loi8O`WNUWkW91I@~2SOD!;qcK+IQaI6@0hP5=nJ)1>~1~cZ;L88LcUJF zg1dfVsWBP}gxaeWvbtie!9aJ1KccXxezL|r;|r8>9QXSupz0JdeX(dqIMS`K;6N&c z*-3>IdG5fhDl^sv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a_;4BM1p zyk=2`SuK+?Y>-P7ZFt=x|AOR_LYth_*T%iEUhgULkP%x4$vc_PE)s?e0aK>4qkvXK zjhJ5+&`u$P48uzieC;eLe~?4OrD6w&{f53@kXQ|k9OA}{^zZ@3JkJqXjJt<2@jV*c z@_Z)W-BUlJJ>C~%swOkvxK*EA{qXmnaaqNb*r47nPOw?-aq0&X(#8CT(8~f}K!ksn zagm*M2}9fsQ_~2)-NF@2a6f~qm}f$zMa+m(cEl;3OAAH#`3_@p5n;gEh1fcGFwMdZ z6Lp5Y>82$g0xRMLT1zJfB;v@8Man(t%Ak?DsF5h4?Kcf=+5qknj-y9A5#ZvUZ;%B% z!c_wI3GmTRHmcd{2_q1**L@bE!aa;y-cv-AX7$B}_Ay)UKvUBg%XZU1=r*lvO+MZT zgTi~5bHbW$#+szZ?K7}sqy;Nw%%03(T~}lu>1M1MV%ujrE~eF- diff --git a/book/target/classes/ru/molokoin/Publisher.class b/book/target/classes/ru/molokoin/Publisher.class index d36d3162438098d1af5234735b19b6ebe507b87e..b522194fae182c031d5f5b69b9fd5aa6bceb3a07 100644 GIT binary patch delta 1253 zcmZuw-A`L(82`PT)1K4g*)%nkCGbWf$IbW6%u(yYSAdx5hhTywU%{sLwf7qlsGg{4rkS~fFz9m9BzK`K^E26w_XXN#d(D=cZ2 zGUAGo^FYD`aMv2-wwkN1LRZ zHL-I>2d%a&L@ki*8s0))LGHh`v;A}wP^8jlRx9aTnaUUV*HbeK%b7(pIyk3dmEi~R zwb&CiQKxl4|3k6k7YF<&xr6^G_4FQ)`jL1*eJ7J&-1l3~)Z?1iC)aJU!+mlmv-}5m zQugt6hbydM5u-E?D}NIs1g?Jsx@XJdi{)(DBt4s>m8CVszjvHG`o4}6=(6a2sN*!3 zoqas&3^R?FoZmQHmW_X^bmhAZUmZ^*gYrID%IG!vZOLIv1Aj?QTYB0Uv~4vS_!bJ-V?2Nv1V|aeRSHXD46l&et9Ci! zO?)WZF5B96)V0e0zObE4i8(;tZi-A^AKR%_OsP(Zou@OfBjNqC-q8LFyEFB|u%`rP6MM z(4#|x-vh#V9brU7Md{Q+=+$u%QSnO|SnVUI!CwA`f*P(6bh#%h)iqg>`>~*P@tTh7 zh;Y?h%1orq6%RtVsiWVDX=W~AGPOAm1~91N7NNbm?c4`ivjp<%@0^WKh?f~$rQNGbINjNFr$|Jcg%QYOfOV-_o;y1;_JI5dD+1qqZlh{;4^$R+N zaoZA_(a|Qpsv#r4{3w$y%%_$L1WNOYi=S#gxrL#9UL~}_&D9ITgtx4W1yXVPay`*k$%)t*sJob(>=NQ+)l`Tg|PdWxa zL5~Dj`cv^mZ;6lcUmD|vaTYbs@DniDZpM_|Dp GDEtFCp0axY