最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

一個(gè)簡(jiǎn)陋的java圖書管理系統(tǒng)

 更新時(shí)間:2021年03月31日 16:40:05   作者:A_book  
這篇文章主要為大家詳細(xì)介紹了一個(gè)簡(jiǎn)陋的java圖書管理系統(tǒng),簡(jiǎn)單的實(shí)現(xiàn)功能測(cè)試,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文代碼為原創(chuàng)一個(gè)簡(jiǎn)陋的管理系統(tǒng),只做功能的測(cè)試。并沒(méi)有去完善所有應(yīng)有的功能,只做了輸入輸出查找,僅供參考! 

菜單部分: 

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、編號(hào)/2、書名/3、作者");
 }
 public int setMenu(){
 System.out.println("輸入序號(hào):");
 Scanner reader = new Scanner(System.in);
 int num = reader.nextInt();
 if(num >= Min || num <= Max)
 return num;
 else
 return -1;
 }
}

重點(diǎn)的管理部分: 

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("請(qǐng)輸入編號(hào)");
 Find(reader.next(), 0);
 break;
 case 2:
 System.out.println("請(qǐng)輸入書名");
 Find(reader.next(), 1);
 break;
 case 3:
 System.out.println("請(qǐng)輸入作者");
 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 "沒(méi)有找到";
 }
 public String message(){
 Scanner reader = new Scanner(System.in);
 String str = "";
 String s = "";
 System.out.println("請(qǐng)輸入編號(hào)");
 str = reader.next();
 if(findNum(str,0).compareTo("沒(méi)有找到") != 0){
 System.out.println("此編號(hào)存在輸入錯(cuò)誤");
 return "@@!!";
 }
 s += str + "#";
 System.out.println("請(qǐng)輸入書名");
 str = reader.next();
 s += str + "#";
 System.out.println("請(qǐng)輸入作者");
 str = reader.next();
 s += str + "#\n";
 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("\n*********************");
 return book;
 }
}

主函數(shù)部分:/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;
 }
 }
 }

}

關(guān)于管理系統(tǒng)的更多內(nèi)容請(qǐng)點(diǎn)擊《管理系統(tǒng)專題》進(jìn)行學(xué)習(xí)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

泗洪县| 扶绥县| 潼南县| 渝北区| 桐城市| 商丘市| 万宁市| 长阳| 南开区| 苏尼特右旗| 湄潭县| 广南县| 蓝田县| 合作市| 彰化县| 宽甸| 黔江区| 会泽县| 苍山县| 安多县| 华池县| 新密市| 德阳市| 平原县| 微博| 乐清市| 松潘县| 宜城市| 盘锦市| 潮安县| 璧山县| 贞丰县| 邵武市| 金门县| 突泉县| 南安市| 广东省| 大冶市| 府谷县| 北票市| 雷波县|