package practice;
import java.util.Scanner;
class Book {
String Bookcode; //도서 번호
String Bookname; // 책 이름
String Publisher; // 출판사
int amount; //재고
Book(String bookcode, String bookname, String publisher, int amount) {
this.Bookcode=bookcode;
this.Bookname=bookname;
this.Publisher=publisher;
this.amount=amount;
}
}
public class practice1 {
public static void main(String[] args) {
int count = 0;
Book[] list = new Book[5];
while(true) {
System.out.println("---------------BOOKStore---------------");
System.out.println("1. 도서 등록");
System.out.println("2. 도서 검색");
System.out.println("3. 전체 도서 확인");
System.out.println("4. 종료");
System.out.println("---------------BOOKStore---------------");
System.out.print("번호 : " );
Scanner input = new Scanner(System.in);
int num = input.nextInt();
switch (num) {
case 1:
if(count>=5) {
System.out.println("더이상 등록할 수 없습니다.");
}else{
System.out.println("도서 등록 메뉴 입니다");
System.out.print("도서 번호를 입력 해 주세요 >>");
String code = input.next();
System.out.print("도서 이름을 입력 해 주세요 >>");
String name = input.next();
System.out.print("도서 출판사를 입력 해 주세요 >>");
String pub = input.next();
System.out.print("재고를 입력 해 주세요 >>");
int am = input.nextInt();
list[count] = new Book(code, name, pub, am);
count++;
}
break;
case 2:
System.out.print("찾으실 도서를 검색 하세요 : ");
String search = input.next();
for (int i = 0; i < count; i++) {
if(list[i].Bookname.contains(search)) {
System.out.println("도서 번호 : " + list[i].Bookcode);
System.out.println("도서 이름 : " + list[i].Bookname);
System.out.println("출판사 : " + list[i].Publisher);
System.out.println("재고 : " + count);
}else {
System.out.println("찾으시는 도서가 없습니다.");
}
}
break;
case 3:
System.out.println("전체 도서를 검색 합니다.");
for (int i = 0; 0 < count; i++) {
System.out.println(list[i].Bookname);
}
break;
case 4:
System.out.println("시스템을 종료합니다..");
System.exit(-1);
break;
default:
break;
}
}
}
}
'Backend > JAVA' 카테고리의 다른 글
[JAVA] 상속(Inheritance) (0) | 2022.04.22 |
---|---|
[JAVA] Singleton Pattern (0) | 2022.04.21 |
[JAVA] 간단한 커피 자판기 프로그램 (0) | 2022.04.17 |
[JAVA] 간단한 은행 입 출금 프로그램 (0) | 2022.04.17 |
[JAVA] 간단한 사칙 연산 계산기 (0) | 2022.04.17 |