この記事のコードは、機能テストのみを実行するオリジナルの単純な管理システムです。すべての適切な機能は改善されていませんが、参照のみで入力と出力を検索しました!
メニューセクション:
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、number/2、book title/3、著者"); } public intmenu(){system.out.println( "入力シリアル番号:");スキャナーreader = new scanner(system.in); int num = reader.nextint(); if(num> = min || num <= max)return num;それ以外の場合は-1; }}主要な管理部品:
Import java.io.file; import java.io.filenotfoundexception; Import java.io.fileoutputStream; Import java.util.scanner; Import java.io.io.ioexception; public class book {public void find(){メニューメニュー= new Menu(); menu.getFindMenu();スキャナーreader = new scanner(system.in); int num = menu.setmenu(); switch(num){case 1:system.out.println( "番号を入力してください"); find(reader.next()、0);壊す;ケース2:System.out.println( "本のタイトルを入力してください"); find(reader.next()、1);壊す;ケース3:system.out.println( "著者を入力してください"); find(reader.next()、2);壊す; }} 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(); } "not not inge"を返します。 } public string message(){scanner reader = new scanner(system.in);文字列str = "";文字列s = ""; system.out.println( "番号を入力してください"); str = reader.next(); if(findnum(str、0).compareto( "not not")!= 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)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(); }最後に{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( "/n ************************");戻る本; }}主な関数部分:
public class managebook {public static void main(string [] agse){メニューメニュー= new Menu(); book book = new book(); while(true){menu.getMenu(); int num = menu.setmenu(); switch(num){case 1:book.getbook();壊す;ケース2:book.setbook();壊す;ケース3:book.find();壊す;ケース-1:system.out.println( "入力は間違っていない");壊す; }}}}管理システムの詳細については、「管理システムの特別トピック」をクリックして学習してください
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。