Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lhe #3

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/24_2_BE_Beginner_Week2_team2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import java.time.LocalDate;

public class Book<T> {
private String title;
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, String author, String publisher, String ISBN, LocalDate publishDate) {
this.title = title;
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 LocalDate getDueDate() {
return dueDate;
}

public T getLoanedBy() {
return loanedBy;
}

public void setLoanedBy(T loanedBy) {
this.loanedBy = loanedBy;
this.isLoaned = true;
}

//책 정보 출력
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.");
}
}
}

6 changes: 6 additions & 0 deletions BookNotFoundException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class BookNotFoundException extends Exception {
//생성자
public BookNotFoundException(String msg) {
super(msg);
}
}
108 changes: 108 additions & 0 deletions Library.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@

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<T> {
// 변수 선언부
private static final String address = "부산 남구 용소로 45";
private String name; // 도서관 이름
private List<Book> bookList;
private T userContainer;

public Library(String name) {
this.name = name;
this.bookList = new ArrayList<>();
}

//BookNotFoundException 커스텀 예외 클래스에서 예외 처리하기 위한 메서드 작성
public Optional<Book> findBook(String title) throws BookNotFoundException {
for(Book book : bookList){ // bookList에 생성된 Book 객체 순회.
if(book.getTitle().equals(title)) {
return Optional.of(book);
}
}
return Optional.empty(); //책 찾지 못했을 때 빈 optional 반환.
}

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
LibraryController lc = new LibraryController();

public void showLibraryMemu() throws IOException {

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("사용할 메뉴 : ");

int num = Integer.parseInt(br.readLine());

switch(num) {
case 1 :

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("번호를 다시 입력해주세요.");
}

}
}
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());

// Book 클래스 생성자를 사용해 책 객체 생성
Book book = new Book(title, author, publisher, ISBN, publishDate);
bookList.add(book);
return book;
}

public static void main(String[] args) throws IOException {
Library pknuL = new Library("중앙도서관");
pknuL.showLibraryMemu();

}
}

3 changes: 3 additions & 0 deletions LibraryController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class LibraryController {

}
13 changes: 13 additions & 0 deletions LibrarySystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import java.awt.print.Book;
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<Book> findBook(String title);
Optional<Users> findUser(int userId);
}
15 changes: 15 additions & 0 deletions Pair.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Pair<T extends Object> {
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;
}
}
Loading