허름한 자바 도서 관리 시스템
메뉴 섹션:
import java.util.Scanner;
public class Menu {
int Min = 1;
int Max = 3;
public void getMenu(){
System.out.println("1、 /2、 /3、 ");
}
public void getFindMenu(){
System.out.println("1、 /2、 /3、 ");
}
public int setMenu(){
System.out.println(" :");
Scanner reader = new Scanner(System.in);
int num = reader.nextInt();
if(num >= Min || num <= Max)
return num;
else
return -1;
}
}
중점적인 관리 부분:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Scanner;
import java.io.IOException;
public class Book {
public void find(){
Menu menu = new Menu();
menu.getFindMenu();
Scanner reader = new Scanner(System.in);
int num = menu.setMenu();
switch(num){
case 1:
System.out.println(" ");
Find(reader.next(), 0);
break;
case 2:
System.out.println(" ");
Find(reader.next(), 1);
break;
case 3:
System.out.println(" ");
Find(reader.next(), 2);
break;
}
}
public void Find(String s,int n){
try {
Scanner in = new Scanner(new File("res/Book.txt"));
while (in.hasNextLine()) {
String str = in.nextLine();
String[] book = str.trim().split("#");
if(book[n].compareTo(s) == 0)
System.out.println(book[0] +" "+ book[1] +" "+ book[2]);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public String findNum(String s,int n){
try {
Scanner in = new Scanner(new File("res/Book.txt"));
while (in.hasNextLine()) {
String str = in.nextLine();
String[] book = str.trim().split("#");
if(book[n].compareTo(s) == 0)
return book[n];
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return " ";
}
public String message(){
Scanner reader = new Scanner(System.in);
String str = "";
String s = "";
System.out.println(" ");
str = reader.next();
if(findNum(str,0).compareTo(" ") != 0){
System.out.println(" ");
return "@@!!";
}
s += str + "#";
System.out.println(" ");
str = reader.next();
s += str + "#";
System.out.println(" ");
str = reader.next();
s += str + "#
";
return s;
}
public void setBook() {
FileOutputStream fop = null;
File file;
String content = message();
if(content.compareTo("@@!!") == 0)
return ;
try {
file = new File("res/Book.txt");
fop = new FileOutputStream(file,true);
byte[] contentInBytes = content.getBytes();
fop.write(contentInBytes);
fop.flush();
fop.close();
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fop != null) {
fop.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void getBook() {
try {
Scanner in = new Scanner(new File("res/Book.txt"));
while (in.hasNextLine()) {
String str = in.nextLine();
splitt(str);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public static String[] splitt(String str) {
String[] book = str.trim().split("#");
for (int i = 0; i < book.length; i++) {
System.out.println(book[i]);
}
System.out.println("
*********************");
return book;
}
}
주 함수 섹션:/strong>
public class ManageBook {
public static void main(String[] agse){
Menu menu = new Menu();
Book book = new Book();
while(true){
menu.getMenu();
int num = menu.setMenu();
switch(num){
case 1:
book.getBook();
break;
case 2:
book.setBook();
break;
case 3:
book.find();
break;
case -1:
System.out.println(" ");
break;
}
}
}
}
관리 시스템에 대한 더 많은 내용을 클릭하십시오《관리 시스템 테마》. 학습 진행이상은 본문의 전체 내용입니다. 여러분의 학습에 도움이 되고 저희를 많이 응원해 주십시오.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
38. Java의 Leetcode 솔루션텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.