国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

一個簡陋的java圖書管理系統

2019-11-26 14:04:35
字體:
來源:轉載
供稿:網友

本文代碼為原創一個簡陋的管理系統,只做功能的測試。并沒有去完善所有應有的功能,只做了輸入輸出查找,僅供參考! 

菜單部分: 

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 + "#/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; }}

主函數部分:

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;  } } }}

關于管理系統的更多內容請點擊《管理系統專題》進行學習

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高淳县| 祁连县| 罗山县| 鹰潭市| 美姑县| 云霄县| 故城县| 景泰县| 岑溪市| 张家界市| 富民县| 和林格尔县| 佛坪县| 博湖县| 小金县| 米泉市| 临沭县| 莆田市| 绍兴市| 漳浦县| 临澧县| 洪泽县| 马尔康县| 友谊县| 六枝特区| 沙田区| 松江区| 竹溪县| 盐亭县| 勐海县| 剑川县| 新和县| 安新县| 长治市| 莆田市| 盐亭县| 哈巴河县| 丹江口市| 津南区| 灵丘县| 安西县|