import java.util.Scanner;
import java.util.*;
public class lib {
static ArrayList sample = new ArrayList();
static Scanner scn = new Scanner(System.in);
static public String menu()
{
String temp;
int num;
while(true)
{
System.out.print("원하는 기능 선택: 1.도서관 초기화 2. 책 검색 3. 책 등록 4. 책 삭제 5. 책 대출 6. 책 반납 7. 전체 목록 8. 종료 ===>" );
temp = scn.nextLine();
num = Integer.parseInt(temp);
if(num >= 1 && num <= 8)
return(temp);
else
System.out.println("에러");
}
}
static private int checkBookNum(int bookNum)
{
int used=1;
TextBook element;
for(int i= 0 ; i
{
element =sample.get(i);
if(element.getBookNum() == bookNum)
{
used = 0;
return(used);
}
}
return(used);
}
static public void initLib()
{
int num,bookNum;
String title;
String publisher;
int price;
String pubDate;
String tel;
String author;
String isbn;
String temp;
Random rand = new Random();
System.out.print("도서관에 책이 몇 권인지 입력하세요");
temp = scn.nextLine();
num = Integer.parseInt(temp);
for(int i = 0; i
{
System.out.printf("책 제목을 입력하시오:");
title = scn.nextLine();
System.out.printf("책 출판사를 입력하시오:");
publisher = scn.nextLine();
System.out.printf("책 가격을 입력하시오:");
temp = scn.nextLine();
price = Integer.parseInt(temp);
System.out.printf("책 출판일을 입력하시오:");
pubDate = scn.nextLine();
System.out.printf("책 출판사 전화번호를 입력하시오:");
tel = scn.nextLine();
System.out.printf("책 저자를 입력하시오:");
author = scn.nextLine();
System.out.printf("책 isbn을 입력하시오:");
isbn = scn.nextLine();
do {
bookNum = rand.nextInt(1000);
} while (checkBookNum(bookNum) != 1);
TextBook newBook = new TextBook(bookNum,title,publisher,price,pubDate,tel,author,isbn);
sample.add(newBook);
}
}
static public void insertLib()
{
String title;
String publisher;
int price, bookNum;
String pubDate;
String tel;
String author;
String isbn;
String temp;
Random rand = new Random();
System.out.printf("책 제목을 입력하시오:");
title = scn.nextLine();
System.out.printf("책 출판사를 입력하시오:");
publisher = scn.nextLine();
System.out.printf("책 가격을 입력하시오:");
temp = scn.nextLine();
price = Integer.parseInt(temp);
System.out.printf("책 출판일을 입력하시오:");
pubDate = scn.nextLine();
System.out.printf("책 출판사 전화번호를 입력하시오:");
tel = scn.nextLine();
System.out.printf("책 저자를 입력하시오:");
author = scn.nextLine();
System.out.printf("책 isbn을 입력하시오:");
isbn = scn.nextLine();
do {
bookNum = rand.nextInt(1000);
} while (checkBookNum(bookNum) != 1);
TextBook newBook = new TextBook(bookNum,title,publisher,price,pubDate,tel,author,isbn);
sample.add(newBook);
}
static public void printLib()
{
TextBook bookData;
for(int i = 0; i
{
bookData = sample.get(i);
System.out.println("책 번호" + bookData.getBookNum());
System.out.println("책 제목" + bookData.getTitle());
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String menuNum;
while(true) {
menuNum = menu();
switch(menuNum) {
case "1": initLib();
break;
case "3": insertLib();
break;
case "7": printLib();
break;
case "8": System.out.println("프로그램 종료");
scn.close();
System.exit(0);
}
}
}
}
책제목/저자/출판사으로 검색할 수 있게하고 검색되면 정보 모두 출력하는건데
못하면 자퇴하면 됨?
족뉴비가 조금 못한다고 접어야하면 누가 밥벌어먹고 사냐 니가 하기 싫으면 접어야하긴 하지
이것저것 쑤셔보고 검색해보는데도 모르겠어서 이거 할머리가 아닌거 같음..