이 기사의 코드는 기능 테스트 만 수행하는 원래 간단한 관리 시스템입니다. 그것은 모든 적법한 기능을 개선하지는 않았지만 참조를 위해 입력 및 출력 만 검색했습니다!
메뉴 섹션 :
import java.util.scanner; 공개 클래스 메뉴 {int min = 1; int max = 3; public void getMenu () {System.out.println ( "1, display/2, input/3, find"); } public void getFindMenu () {System.out.println ( "1, 번호/2, Book Title/3, Author"); } public int setMenu () {system.out.println ( "입력 일련 번호 :"); 스캐너 리더 = 새 스캐너 (System.In); int num = reader.nextint (); if (num> = || num <= max) num; 그렇지 않으면 -1; }}주요 관리 부품 :
import java.io.file; import java.io.filenotfoundException; import java.io.fileoutputStream; import java.util.scanner; import java.io.ioexception; public void find () {메뉴 메뉴 = 새 메뉴 (); menu.getFindMenu (); 스캐너 리더 = 새 스캐너 (System.In); int num = menu.setmenu (); switch (num) {case 1 : system.out.println ( "번호를 입력하십시오"); 찾기 (reader.next (), 0); 부서지다; 사례 2 : System.out.println ( "책 제목을 입력하십시오"); 찾기 (reader.next (), 1); 부서지다; 사례 3 : System.out.println ( "저자를 입력하십시오"); 찾기 (reader.next (), 2); 부서지다; }} public void find (string s, int n) {try {scanner in = new Scanner (새 파일 ( "res/book.txt")); while (in.hasnextline ()) {string str = in.nextline (); 문자열 [] 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 (새 파일 ( "res/book.txt")); while (in.hasnextline ()) {string str = in.nextline (); 문자열 [] book = str.trim (). split ( "#"); if (book [n] .compareto (s) == 0) return book [n]; }} catch (filenotfoundException e) {e.printstacktrace (); } "찾을 수 없다"는 반환; } public String Message () {스캐너 리더 = 새 스캐너 (System.In); 문자열 str = ""; 문자열 s = ""; System.out.println ( "번호를 입력하십시오"); str = reader.next (); if (findnum (str, 0) .compareto ( "찾기 없음")! = 0) {System.out.println ( "이 숫자는 입력 오류가 있습니다"); 반품 "@@!!"; } s + = str + "#"; System.out.println ( "제목을 입력하십시오"); str = reader.next (); s + = str + "#"; System.out.println ( "저자를 입력하십시오"); str = reader.next (); s + = str + "#/n"; 반환 s; } public void setbook () {fileoutputStream fop = null; 파일 파일; 문자열 content = message (); if (content.compareto ( "@@ !!") == 0) 반환; try {file = 새 파일 ( "res/book.txt"); fop = 새 fileoutputStream (file, true); 바이트 [] contentInbytes = content.getBytes (); fop.write (contentInBytes); fop.flush (); fop.close (); System.out.println ( "완료"); } catch (ioexception e) {e.printstacktrace (); } 마침내 {try {if (fop! = null) {fop.close (); }} catch (ioexception e) {e.printstacktrace (); }}} public void getbook () {try {scanner in = new Scanner (새 파일 ( "res/book.txt")); while (in.hasnextline ()) {String str = in.nextline (); 분할 (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 ( "/n **************************"); 반환 책; }} 주요 기능 부분 :
public class managebook {public static void main (String [] agse) {menu menu = new Menu (); 책 책 = 새 책 (); while (true) {menu.getMenu (); int num = menu.setmenu (); 스위치 (num) {case 1 : book.getBook (); 부서지다; 사례 2 : book.setbook (); 부서지다; 사례 3 : book.find (); 부서지다; case -1 : system.out.println ( "입력이 잘못되었습니다"); 부서지다; }}}}관리 시스템에 대한 자세한 내용은 "관리 시스템 특별 주제"를 클릭하여 배우십시오.
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.