From a1586e8a38d4f98405fa66aedbdf281e7213b42e Mon Sep 17 00:00:00 2001 From: hanong0321 Date: Sat, 21 Sep 2024 20:46:54 +0900 Subject: [PATCH 1/9] Test 1 --- Library.java | 2 ++ LibrarySystem.java | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 Library.java create mode 100644 LibrarySystem.java diff --git a/Library.java b/Library.java new file mode 100644 index 0000000..7453be2 --- /dev/null +++ b/Library.java @@ -0,0 +1,2 @@ +public class Library { +} diff --git a/LibrarySystem.java b/LibrarySystem.java new file mode 100644 index 0000000..785eadf --- /dev/null +++ b/LibrarySystem.java @@ -0,0 +1,3 @@ +public interface LibrarySystem { + void print(); +} From ac2318628ffc0aa0decd335403d2c11a4f3f4183 Mon Sep 17 00:00:00 2001 From: hanong0321 Date: Sat, 21 Sep 2024 20:47:18 +0900 Subject: [PATCH 2/9] Test 1 --- .idea/.gitignore | 8 ++++++++ .idea/24_2_BE_Beginner_Week2_team2.iml | 11 +++++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ 5 files changed, 39 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/24_2_BE_Beginner_Week2_team2.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/24_2_BE_Beginner_Week2_team2.iml b/.idea/24_2_BE_Beginner_Week2_team2.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/.idea/24_2_BE_Beginner_Week2_team2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1b2d693 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d59629e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From d4fd212559006ebf47ca6d26f98177483f1cadd1 Mon Sep 17 00:00:00 2001 From: hanong0321 Date: Sat, 21 Sep 2024 21:26:29 +0900 Subject: [PATCH 3/9] Test 1 --- Library.java | 57 +++++++++++++++++++++++++++++++++++++++++++++- LibrarySystem.java | 12 ++++++++-- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/Library.java b/Library.java index 7453be2..0296c84 100644 --- a/Library.java +++ b/Library.java @@ -1,2 +1,57 @@ -public class Library { +import java.awt.print.Book; +import java.util.*; + +public class Library implements LibrarySystem{ + private static final String address = "부산 남구 용소로 45"; + private String name; + private List bookList; + private List userList; + private Book book; + private Users user; + + @Override + public Optional findBook(String title) { + return Optional.empty(); + } + + @Override + public Optional findUser(int userId) { + return Optional.empty(); + } + + @Override + public void addBook(Book book) { + + } + + @Override + public void addUser(Users User) { + + } + + @Override + public void returnBook(Book book) { + + } + + public static void main(String[] args) { + + lhe + // pknuLibrary.users() // 유저 생성 } + +class BookNotFoundException extends Exception{ + //생성자 + public BookNotFoundException(String msg){ + super(msg); + } +} + +class UserNotFoundException extends Exception{ + //생성자 + public UserNotFoundException(String msg){ + super(msg); + } +} + + diff --git a/LibrarySystem.java b/LibrarySystem.java index 785eadf..886c7a2 100644 --- a/LibrarySystem.java +++ b/LibrarySystem.java @@ -1,3 +1,11 @@ -public interface LibrarySystem { - void print(); +import java.awt.print.Book; +import java.util.Optional; + +interface LibrarySystem{ + Optional findBook(String title); + Optional findUser(int userId); + void addBook(Book book); + void addUser(Users User); + void returnBook(Book book); + } From 9f93034f13585edd15e90aea3b1d2facccd157f3 Mon Sep 17 00:00:00 2001 From: hanong0321 Date: Sat, 21 Sep 2024 21:27:06 +0900 Subject: [PATCH 4/9] Test 3 --- Library.java | 1 + LibrarySystem.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Library.java b/Library.java index 0296c84..a2613e5 100644 --- a/Library.java +++ b/Library.java @@ -12,6 +12,7 @@ public class Library implements LibrarySystem{ @Override public Optional findBook(String title) { return Optional.empty(); + //dlkajdf } @Override diff --git a/LibrarySystem.java b/LibrarySystem.java index 886c7a2..a5bd5d8 100644 --- a/LibrarySystem.java +++ b/LibrarySystem.java @@ -7,5 +7,5 @@ interface LibrarySystem{ void addBook(Book book); void addUser(Users User); void returnBook(Book book); - + //dd } From d9d37a4bdd51dd5ef9fda92fd5f786607edb4af0 Mon Sep 17 00:00:00 2001 From: hanong0321 Date: Sat, 21 Sep 2024 21:28:30 +0900 Subject: [PATCH 5/9] Test 3 --- Library.java | 4 ++-- LibrarySystem.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Library.java b/Library.java index a2613e5..d4ffc2e 100644 --- a/Library.java +++ b/Library.java @@ -29,7 +29,7 @@ public void addBook(Book book) { public void addUser(Users User) { } - + //ddd @Override public void returnBook(Book book) { @@ -37,7 +37,7 @@ public void returnBook(Book book) { public static void main(String[] args) { - lhe + // pknuLibrary.users() // 유저 생성 } diff --git a/LibrarySystem.java b/LibrarySystem.java index a5bd5d8..93f9b7b 100644 --- a/LibrarySystem.java +++ b/LibrarySystem.java @@ -7,5 +7,5 @@ interface LibrarySystem{ void addBook(Book book); void addUser(Users User); void returnBook(Book book); - //dd + //dddd } From 16c560ca775bcb339d4202675cfe0143cb3b7051 Mon Sep 17 00:00:00 2001 From: hanong0321 Date: Sat, 21 Sep 2024 21:29:56 +0900 Subject: [PATCH 6/9] Test 3 --- Library.java | 2 +- LibrarySystem.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library.java b/Library.java index d4ffc2e..e44cfae 100644 --- a/Library.java +++ b/Library.java @@ -29,7 +29,7 @@ public void addBook(Book book) { public void addUser(Users User) { } - //ddd + //ddddd @Override public void returnBook(Book book) { diff --git a/LibrarySystem.java b/LibrarySystem.java index 93f9b7b..9cc3104 100644 --- a/LibrarySystem.java +++ b/LibrarySystem.java @@ -7,5 +7,5 @@ interface LibrarySystem{ void addBook(Book book); void addUser(Users User); void returnBook(Book book); - //dddd + //ddddddd } From cb037d4dde20c2167fe43d62224fae6aecd5ec26 Mon Sep 17 00:00:00 2001 From: hanong0321 Date: Sun, 22 Sep 2024 21:52:24 +0900 Subject: [PATCH 7/9] Test 3 --- .idea/uiDesigner.xml | 124 +++++++++++++++++++++++++++++++++++++++++++ Book.java | 25 +++++++++ Library.java | 82 ++++++++++++++++++++-------- LibrarySystem.java | 10 ++-- Users.java | 22 ++++++++ 5 files changed, 236 insertions(+), 27 deletions(-) create mode 100644 .idea/uiDesigner.xml create mode 100644 Book.java create mode 100644 Users.java diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Book.java b/Book.java new file mode 100644 index 0000000..07c7ad9 --- /dev/null +++ b/Book.java @@ -0,0 +1,25 @@ +public class Book { + private String title; + private boolean isBorrowed; + + public Book(String title) { + this.title = title; + this.isBorrowed = false; + } + + public String getTitle() { + return title; + } + + public boolean isBorrowed() { + return isBorrowed; + } + + public void borrow() { + this.isBorrowed = true; + } + + public void returnBook() { + this.isBorrowed = false; + } +} \ No newline at end of file diff --git a/Library.java b/Library.java index e44cfae..fc61584 100644 --- a/Library.java +++ b/Library.java @@ -1,58 +1,94 @@ + import java.awt.print.Book; import java.util.*; -public class Library implements LibrarySystem{ +public class Library implements LibrarySystem { + // 변수 선언부 private static final String address = "부산 남구 용소로 45"; - private String name; + private String name; // 도서관 이름 private List bookList; - private List userList; - private Book book; - private Users user; + public Library(String name) { + this.name = name; + this.bookList = new ArrayList<>(); + } + + //인터페이스 구현부 @Override - public Optional findBook(String title) { - return Optional.empty(); - //dlkajdf + public void addUser(int userId, String name) { + Users.addUser(userId, name); } @Override - public Optional findUser(int userId) { - return Optional.empty(); + public void removeUser(int userId) { + //Users.removeUser(userId); } + /* + @Override + public void addBook(Book book, int userId) { + if(Users.checkExistUser(userId)) { + bookList.add(book); + System.out.println(/*book.getTitle() + "책 추가가 완료"); + else { + // throw new BookNotFoundException("책 추가 실패, 사용자 ID 존재 X"); + } + } + */ @Override - public void addBook(Book book) { + public void addBook(Book book, int userId) throws BookNotFoundException { + Optional user = findUser(userId); + if(user.isPresent()) { + bookList.add(book); + System.out.println("책 추가 완료"); + } else { + throw new BookNotFoundException("책 추가 실패, 사용자 ID 존재 X"); + } + } + + @Override + public void borrowBook(int userId, String bookTitle) { + Optional book = findBook(bookTitle); } @Override - public void addUser(Users User) { + public void returnBook(int userId, String bookTitle) { } - //ddddd + @Override - public void returnBook(Book book) { + public Optional findBook(String title) { + for(Book book : bookList) { + if(book.getTitle().equals(title)) { // 왜 못쓰는거지?? 하... + return Optional.of(book); + } + } + return Optional.empty(); + } + @Override + public Optional findUser(int userId) { + return Optional.empty(); } public static void main(String[] args) { + Library pknuL = new Library("중앙도서관"); + pknuL.addUser(202112343, "이한응"); + pknuL.addBook("총 균 쇠", 202112343); - - // pknuLibrary.users() // 유저 생성 + } } - -class BookNotFoundException extends Exception{ +class BookNotFoundException extends Exception { //생성자 - public BookNotFoundException(String msg){ + public BookNotFoundException(String msg) { super(msg); } } -class UserNotFoundException extends Exception{ +class UserNotFoundException extends Exception { //생성자 - public UserNotFoundException(String msg){ + public UserNotFoundException(String msg) { super(msg); } } - - diff --git a/LibrarySystem.java b/LibrarySystem.java index 9cc3104..38e12c6 100644 --- a/LibrarySystem.java +++ b/LibrarySystem.java @@ -2,10 +2,12 @@ import java.util.Optional; interface LibrarySystem{ + void addUser(int userId, String name); + void removeUser(int userId); + void addBook(Book book, int userId); + void borrowBook(int userId, String bookTitle); + void returnBook(int userId, String bookTitle); + Optional findBook(String title); Optional findUser(int userId); - void addBook(Book book); - void addUser(Users User); - void returnBook(Book book); - //ddddddd } diff --git a/Users.java b/Users.java new file mode 100644 index 0000000..7734d1a --- /dev/null +++ b/Users.java @@ -0,0 +1,22 @@ +import java.util.HashMap; +import java.util.Map; + +public class Users { + private static Map userList = new HashMap<>(); + + // 회원 등록 + public static void addUser(int userId, String name) { + userList.put(userId, name); + } + public static void removeUser(int userId) { + if(userList.remove(userId) != null) { + System.out.println("회원 탈퇴 완료"); + } else { + //throw new UserNotFoundException("회원 ID 존재 하지 않음"); + } + } + public static boolean checkExistUser(int userId) { + return userList.containsKey(userId); + } + +} From c6ff2426a660a30f060f899811980fe30c90b3c2 Mon Sep 17 00:00:00 2001 From: hanong0321 Date: Sun, 22 Sep 2024 21:53:30 +0900 Subject: [PATCH 8/9] =?UTF-8?q?=EB=AF=B8=EC=99=84=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.idea/.gitignore | 8 ++ .../.idea/24_2_BE_Beginner_Week2_team2.iml | 11 +++ .../.idea/misc.xml | 6 ++ .../.idea/modules.xml | 8 ++ .../.idea/vcs.xml | 6 ++ .../24_2_BE_Beginner_Week2_team2/Book.class | Bin 0 -> 691 bytes .../BookNotFoundException.class | Bin 0 -> 337 bytes .../Library.class | Bin 0 -> 2242 bytes .../LibrarySystem.class | Bin 0 -> 502 bytes .../24_2_BE_Beginner_Week2_team2/README.md | 70 ++++++++++++++++++ .../UserNotFoundException.class | Bin 0 -> 337 bytes .../24_2_BE_Beginner_Week2_team2/Users.class | Bin 0 -> 1266 bytes 12 files changed, 109 insertions(+) create mode 100644 out/production/24_2_BE_Beginner_Week2_team2/.idea/.gitignore create mode 100644 out/production/24_2_BE_Beginner_Week2_team2/.idea/24_2_BE_Beginner_Week2_team2.iml create mode 100644 out/production/24_2_BE_Beginner_Week2_team2/.idea/misc.xml create mode 100644 out/production/24_2_BE_Beginner_Week2_team2/.idea/modules.xml create mode 100644 out/production/24_2_BE_Beginner_Week2_team2/.idea/vcs.xml create mode 100644 out/production/24_2_BE_Beginner_Week2_team2/Book.class create mode 100644 out/production/24_2_BE_Beginner_Week2_team2/BookNotFoundException.class create mode 100644 out/production/24_2_BE_Beginner_Week2_team2/Library.class create mode 100644 out/production/24_2_BE_Beginner_Week2_team2/LibrarySystem.class create mode 100644 out/production/24_2_BE_Beginner_Week2_team2/README.md create mode 100644 out/production/24_2_BE_Beginner_Week2_team2/UserNotFoundException.class create mode 100644 out/production/24_2_BE_Beginner_Week2_team2/Users.class diff --git a/out/production/24_2_BE_Beginner_Week2_team2/.idea/.gitignore b/out/production/24_2_BE_Beginner_Week2_team2/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/out/production/24_2_BE_Beginner_Week2_team2/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/out/production/24_2_BE_Beginner_Week2_team2/.idea/24_2_BE_Beginner_Week2_team2.iml b/out/production/24_2_BE_Beginner_Week2_team2/.idea/24_2_BE_Beginner_Week2_team2.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/out/production/24_2_BE_Beginner_Week2_team2/.idea/24_2_BE_Beginner_Week2_team2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/24_2_BE_Beginner_Week2_team2/.idea/misc.xml b/out/production/24_2_BE_Beginner_Week2_team2/.idea/misc.xml new file mode 100644 index 0000000..1b2d693 --- /dev/null +++ b/out/production/24_2_BE_Beginner_Week2_team2/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/24_2_BE_Beginner_Week2_team2/.idea/modules.xml b/out/production/24_2_BE_Beginner_Week2_team2/.idea/modules.xml new file mode 100644 index 0000000..d59629e --- /dev/null +++ b/out/production/24_2_BE_Beginner_Week2_team2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/24_2_BE_Beginner_Week2_team2/.idea/vcs.xml b/out/production/24_2_BE_Beginner_Week2_team2/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/out/production/24_2_BE_Beginner_Week2_team2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/24_2_BE_Beginner_Week2_team2/Book.class b/out/production/24_2_BE_Beginner_Week2_team2/Book.class new file mode 100644 index 0000000000000000000000000000000000000000..7e1f6660e4b59bab98466bbd11a47637e1206128 GIT binary patch literal 691 zcmZuv%TB^T6g^Y=pruem5PT-?peC|$hjD?4D4*+c(Sx}HMpxV%&GZZJ@gV&sT;keoLC&4gb(9e0ulM9AS zy)iJ6g=xUDk%P^kwxj5dK}&ct4H!zDUwAKxc{pwfK*5HCB7?X&&e0GGH7DIL%B>mJ-x!zb; zkV!~g_oW%~6$i;Y4$~}FFPg{0;ED@9Q}j+nC>&D|g=VJEOW9>bsc6?g6TlX&B|3HG z4Zv~Vz}%As3^%ht{zU?|X)QsOAQd`H7$^{NnL0a?-a&;b@i7> z^onpK{&gD?I?GiZdjE_;$Y!>6l`3>_&xJ0XbWaySh-0L@XL!WHn{wV_G-5XJ$=Ue} j=$Wes8Ru{nV8Y4*+gu&4Rmic!i1pY-_sgrtD8k++h(t=I literal 0 HcmV?d00001 diff --git a/out/production/24_2_BE_Beginner_Week2_team2/Library.class b/out/production/24_2_BE_Beginner_Week2_team2/Library.class new file mode 100644 index 0000000000000000000000000000000000000000..1d48c90bdb23fff6581e04daac651f39a5fcd86c GIT binary patch literal 2242 zcma)7+in|G6kW%5Jhn5r;3O`M3w61)zJ$7k6k41nZ9)qHHz_!ENXl*OOp{6M8EZUl z$y-zfo+_bA^dTsHK=1$(4=KtGD)9k)N@6|%#6EMzm!ytV$sW&~v-jF-uf68@@BjY% z3&1D}0l46n;E~Y=FGKgDa#u+f6n#E9nOjuz7K3+4(=}_D!5xid{qVsrAt0k2GJ}-X za;9P~GkA2Rs4@i84Si$m;0(b*wB_w5> z!}*$e2eYa762~g&hsZgy^VWTMOU58BkhFI+eQuQGWr#L+QVVX9d$MF{hOQJy@^^4i z!X+8+B1NNZ2vZB8IjF^wMdJ@eW33>3xXjR1{rO?_(c1oZtJT%@z0DQQYlQplyjyPn zciM+h27mSO=0A_ttB)V@T^jT?h7QMEH7WV5O|?u@?-(=mvZd%&Rw-0eAI2H__qSK7 z_ctQ@_kY>j`YlrZ;n(W75B7gtj|@`x{){%SD^|rMhn{KT$p<_no|Su6($+J{RZ0z0 z!=5o?juN`knyyY%iaFJsQgQ{`y#?muej)TEri%7WGF0>!NI%B}$Gwr`L{#wT&x8J4SD73rf^Nr1j2F znkSaUFpG*tZ%Qb7TR_-HT+RJlWW}7P@%6OWCYP6%^h%m$m@z75UcIhyIb~${kRU9?%$^))`bt~ONXU>Psbdse`w!-1V7!=TR_(|t=yta7yb6dcfjI_ zElBaF=$P3-*A}{;*eN&Y8ia?g9dzv^fG+f+8xyn=63LjvO?o02yC`{&ADB)FPQ^`o z-tfRKdK;MhPk?8%5emnOh^RW27a!vj!k|nWl{cEfl!JPK)_Fc_0DA4G@1gpD5;VRd||u8M@)G+-A+GOGC* z@%)?sxdp_^7qr6gWxeEx&7*~4=b9RMRxwI&3Ne1FQ$g;Vi?qt+_w3^B4f=K2B8dqM zHch}&C+@*lHaX!#h4ORAKL^^SBhZ971lk;#QpFv@778Pv=z@wLwrD*tWjQI?uI{c{p7esS2J)4BbR#1t%B5@c2*JsIk2Va + + - 각 클래스는 다른 팀원의 클래스와 **조합** 또는 **상속**을 통해 상호작용해야 합니다. + - **조합은 팀내에서 최소 한번 이상 사용**되어야 하며, **생성자 주입 방식**을 사용하는 것을 권장합니다. + + + +- **팀 내 최소 1번은 다음의 자바 요소를 사용**해야합니다.(모두가 구현할 필요는 없습니다) + + + +- **깃허브 관련 요구사항** + + \ No newline at end of file diff --git a/out/production/24_2_BE_Beginner_Week2_team2/UserNotFoundException.class b/out/production/24_2_BE_Beginner_Week2_team2/UserNotFoundException.class new file mode 100644 index 0000000000000000000000000000000000000000..4587f913d38e094d858d9a02d23d7040cd0ac4fa GIT binary patch literal 337 zcmZut%TB{E5FDo=fe>gZ05!Dn$o;=l*+QHV7l zfdpP@wKJX_?e5$A%PW9$^fN^0q=<8@AraWURrhL8D^m?F9!h=Z$r^!VM27rWVDCu& z2{1JKB^fL~^HTvFkbdprw593tgC!xJ35Dd!DFV`c-NoSZ&G jJaH8v;~cI6NLF5AldJtN6>@AbVm-Fe{q*WFim>wmtLRGG literal 0 HcmV?d00001 diff --git a/out/production/24_2_BE_Beginner_Week2_team2/Users.class b/out/production/24_2_BE_Beginner_Week2_team2/Users.class new file mode 100644 index 0000000000000000000000000000000000000000..c1ec60ba57e95d6be7feeeccd01a53d683eece1b GIT binary patch literal 1266 zcmZuwOHyQHxM+LTFCM%Fr`3l?tG zrCT?mBcd}dUHDgozueiZ+JU20_-e^^$HeNUOYD*XN!wbS1MXH{X%qMWmzXK&ON*1>NXji0xw_ zVJmea9!vT%UGeFI9zVPnB+z>m9K|sz*3v80Rh?nr5VS*bBRGMR68aRJ!s&hO%dgdJ zy+Y!uLR_b-#HgwdEyJ|)wx#n*I*c<69Xs#Vx8J|%+j;SN=hc_K?YA%gd{~z;fO8U( z3Q`zkXm={!pG|#R5m;rD;QeX|+%QY&R6!JWUcm(nGeotjX>-G@-P70pi}%`)nwM~K zcR~ z;(#}{&J)8RyQ6mDLbQ049Lw8WTc(;l0dZ|n*OsTB(`Gl~=4szETG_h_IbW??nm%KQ zDr6B=8y0M|5MjD4fV|>Z$X=#b09WYJ=yK3Z->c+N$uhD{gPUNVoRDku6@LREjL=sk zQvgOWMmB=$xIrF~Jd2=1lGuRM`wg+7Ewl&mqyZ!DTcpHEg@EdE!;waYUO)mjF-~9+ zOyHIWnx_~+*yDk2;Ya|#5Z%D>w*Id;E6{@wBI9I*yaZx&nyo&uJs!htCzf>+!6c?U zf>Dnkwns1&z(pHnP@it%(q~9Q81q4hMo&AiGyeeX CGZ91p literal 0 HcmV?d00001 From 27e95153df797086310a96ba652123ff2999c731 Mon Sep 17 00:00:00 2001 From: hanong0321 Date: Mon, 23 Sep 2024 21:25:31 +0900 Subject: [PATCH 9/9] =?UTF-8?q?BookAdd()=20=EB=A9=94=EC=84=9C=EB=93=9C,=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20(findbook)=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Book.java | 55 ++++++++++++--- BookNotFoundException.java | 6 ++ Library.java | 140 ++++++++++++++++++++----------------- LibraryController.java | 3 + Pair.java | 15 ++++ Role.java | 16 +++++ User.java | 45 ++++++++++++ UserContainer.java | 20 ++++++ UserNotFoundException.java | 6 ++ 9 files changed, 232 insertions(+), 74 deletions(-) create mode 100644 BookNotFoundException.java create mode 100644 LibraryController.java create mode 100644 Pair.java create mode 100644 Role.java create mode 100644 User.java create mode 100644 UserContainer.java create mode 100644 UserNotFoundException.java diff --git a/Book.java b/Book.java index 07c7ad9..5bd06eb 100644 --- a/Book.java +++ b/Book.java @@ -1,25 +1,58 @@ -public class Book { +import java.time.LocalDate; + +public class Book { private String title; - private boolean isBorrowed; + private String author; + private String publisher; + private String ISBN; + private LocalDate publishDate; + private boolean isLoaned; //대출 여부 + private T loanedBy; //대출한 사용자 정보 + private LocalDate dueDate; //반납 예정일 - public Book(String title) { + //생성자 + public Book(String title, String author, String publisher, String ISBN, LocalDate publishDate) { this.title = title; - this.isBorrowed = false; + this.author = author; + this.publisher = publisher; + this.ISBN = ISBN; + this.publishDate = publishDate; + this.isLoaned = false; + this.dueDate = null; } + //Getter,Setter + public String getTitle() { return title; } - public boolean isBorrowed() { - return isBorrowed; + public LocalDate getDueDate() { + return dueDate; } - public void borrow() { - this.isBorrowed = true; + public T getLoanedBy() { + return loanedBy; } - public void returnBook() { - this.isBorrowed = false; + public void setLoanedBy(T loanedBy) { + this.loanedBy = loanedBy; + this.isLoaned = true; } -} \ No newline at end of file + + //책 정보 출력 + public void printBookInfo() { + System.out.println("Title: " + title); + System.out.println("Author: " + author); + System.out.println("Publisher: " + publisher); + System.out.println("ISBN: " + ISBN); + System.out.println("Published on: " + publishDate); + if (isLoaned) { + System.out.println("loaned to: " + loanedBy.toString()); + System.out.println("Due date: " + dueDate); + } else { + System.out.println("Available for loan."); + } + } +} + diff --git a/BookNotFoundException.java b/BookNotFoundException.java new file mode 100644 index 0000000..c4aa10c --- /dev/null +++ b/BookNotFoundException.java @@ -0,0 +1,6 @@ +public class BookNotFoundException extends Exception { + //생성자 + public BookNotFoundException(String msg) { + super(msg); + } +} diff --git a/Library.java b/Library.java index fc61584..207ba56 100644 --- a/Library.java +++ b/Library.java @@ -1,94 +1,108 @@ -import java.awt.print.Book; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.*; -public class Library implements LibrarySystem { +public class Library { // 변수 선언부 private static final String address = "부산 남구 용소로 45"; private String name; // 도서관 이름 private List bookList; + private T userContainer; public Library(String name) { this.name = name; this.bookList = new ArrayList<>(); } - //인터페이스 구현부 - @Override - public void addUser(int userId, String name) { - Users.addUser(userId, name); + //BookNotFoundException 커스텀 예외 클래스에서 예외 처리하기 위한 메서드 작성 + public Optional findBook(String title) throws BookNotFoundException { + for(Book book : bookList){ // bookList에 생성된 Book 객체 순회. + if(book.getTitle().equals(title)) { + return Optional.of(book); + } + } + return Optional.empty(); //책 찾지 못했을 때 빈 optional 반환. } - @Override - public void removeUser(int userId) { - //Users.removeUser(userId); - } + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + LibraryController lc = new LibraryController(); - /* - @Override - public void addBook(Book book, int userId) { - if(Users.checkExistUser(userId)) { - bookList.add(book); - System.out.println(/*book.getTitle() + "책 추가가 완료"); - else { - // throw new BookNotFoundException("책 추가 실패, 사용자 ID 존재 X"); - } - } - */ - @Override - public void addBook(Book book, int userId) throws BookNotFoundException { - Optional user = findUser(userId); - - if(user.isPresent()) { - bookList.add(book); - System.out.println("책 추가 완료"); - } else { - throw new BookNotFoundException("책 추가 실패, 사용자 ID 존재 X"); - } - } + public void showLibraryMemu() throws IOException { - @Override - public void borrowBook(int userId, String bookTitle) { - Optional book = findBook(bookTitle); - } + while(true) { + System.out.println("메뉴를 선택하세요."); + System.out.println("1. 사용자 등록"); + System.out.println("2. 사용자 탈퇴"); + System.out.println("3. 도서 대출"); + System.out.println("4. 도서 반납"); + System.out.println("5. 도서 추가"); + System.out.println("6. 도서 삭제"); + System.out.println("7. 끝내기"); + System.out.println("============================"); + System.out.print("사용할 메뉴 : "); - @Override - public void returnBook(int userId, String bookTitle) { + int num = Integer.parseInt(br.readLine()); - } + switch(num) { + case 1 : - @Override - public Optional findBook(String title) { - for(Book book : bookList) { - if(book.getTitle().equals(title)) { // 왜 못쓰는거지?? 하... - return Optional.of(book); + break; + case 2 : + + break; + case 3 : + + break; + case 4 : + + break; + case 5 : + bookAdd(); + break; + case 6 : + + break; + case 7 : + System.out.println("프로그램을 종료합니다."); + return; + default : + System.out.println("번호를 다시 입력해주세요."); } + } - return Optional.empty(); } + private Book bookAdd() throws IOException { + System.out.println("도서 추가"); + System.out.print("도서명 : "); + String title = br.readLine(); + System.out.print("작가명 : "); + String author = br.readLine(); + //System.out.print("카테고리 : "); + //String category = br.readLine(); + System.out.print("출판사 : "); + String publisher = br.readLine(); + System.out.print("ISBN : "); + String ISBN = br.readLine(); + System.out.print("출판일 : "); + String publishDateString = br.readLine(); + LocalDate publishDate = LocalDate.parse(publishDateString, DateTimeFormatter.ofPattern("yyyyMMdd")); + System.out.print("가격 : "); + int price = Integer.parseInt(br.readLine()); - @Override - public Optional findUser(int userId) { - return Optional.empty(); + // Book 클래스 생성자를 사용해 책 객체 생성 + Book book = new Book(title, author, publisher, ISBN, publishDate); + bookList.add(book); + return book; } - public static void main(String[] args) { + public static void main(String[] args) throws IOException { Library pknuL = new Library("중앙도서관"); - pknuL.addUser(202112343, "이한응"); - pknuL.addBook("총 균 쇠", 202112343); + pknuL.showLibraryMemu(); } } -class BookNotFoundException extends Exception { - //생성자 - public BookNotFoundException(String msg) { - super(msg); - } -} -class UserNotFoundException extends Exception { - //생성자 - public UserNotFoundException(String msg) { - super(msg); - } -} diff --git a/LibraryController.java b/LibraryController.java new file mode 100644 index 0000000..fdeecb8 --- /dev/null +++ b/LibraryController.java @@ -0,0 +1,3 @@ +public class LibraryController { + +} diff --git a/Pair.java b/Pair.java new file mode 100644 index 0000000..498e764 --- /dev/null +++ b/Pair.java @@ -0,0 +1,15 @@ +public class Pair { + private T x; + private T y; + public Pair(T x, T y) { + this.x = x; + this.y = y; + } + + public T getX() { + return x; + } + public T getY() { + return y; + } +} \ No newline at end of file diff --git a/Role.java b/Role.java new file mode 100644 index 0000000..4ddbf8e --- /dev/null +++ b/Role.java @@ -0,0 +1,16 @@ +public enum Role { + STUDENT(0), + PROFESSOR(1), + STAFF(2), + ADMIN(3); + + private final int value; + + Role(int value) { + this.value = value; + } + + public String getRole(int value) { + return Role.values()[value].toString(); + } +} \ No newline at end of file diff --git a/User.java b/User.java new file mode 100644 index 0000000..d3d998e --- /dev/null +++ b/User.java @@ -0,0 +1,45 @@ +import java.util.Queue; + +public class User { + private final String id; + private final String name; + private final String role; + private Queue books; + + /* + * At first, User object had planned to implemented by + * pulling out from somewhere it exists with recognized by id. + * But, User object doesn't come out from DB or somewhere. + * We cannot pull the value of it, which is name, role, out. + * Because it has NO resource of pulling out from. + * And I decided make dummy data of user. + * Therefore, name, role, should have assigned when it generated. + * -- Commented by Jae Min -- + * */ + public User(String id, String name, String role, Queue books) { + this.id = id; + this.name = name; + this.role = role; + this.books = books; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getRole() { + return role; + } + + public Queue getBook() { + return books; + } + + public void returnBook(T book) { + + } +} \ No newline at end of file diff --git a/UserContainer.java b/UserContainer.java new file mode 100644 index 0000000..fd9ac75 --- /dev/null +++ b/UserContainer.java @@ -0,0 +1,20 @@ +import java.util.HashMap; + +public class UserContainer{ + User[] users; + HashMap userMap; + + public Pair getInfo(String id) { + User user = userMap.get(id); + return new Pair<>(user.getName(), user.getRole()); + } + + public void addUser(User user) { + userMap.put(user.getId(), user); + } + + public void removeUser(String id) { + userMap.remove(id); + } + +} \ No newline at end of file diff --git a/UserNotFoundException.java b/UserNotFoundException.java new file mode 100644 index 0000000..b18139c --- /dev/null +++ b/UserNotFoundException.java @@ -0,0 +1,6 @@ +public class UserNotFoundException extends Exception { + //생성자 + public UserNotFoundException(String msg) { + super(msg); + } +}