一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務器之家 - 編程語言 - JAVA教程 - 一個簡陋的java圖書管理系統

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

2020-05-27 11:08A_book JAVA教程

這篇文章主要為大家詳細介紹了一個簡陋的java圖書管理系統,簡單的實現功能測試,感興趣的小伙伴們可以參考一下

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

菜單部分:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
 }
}

重點的管理部分:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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;
 }
}

主函數部分:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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;
  }
 }
 }
 
}

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 青青久久精品国产免费看 | 国产重口老太伦 | 奇米白色 | 四虎影在线永久免费观看 | 高人先生免费观看全集 | 欧美一区二区三区gg高清影视 | 小伙无套内射老女人 | av毛片在线看 | 国产在线麻豆波多野结衣 | www.麻豆视频 | chinese真实incest chinese特色video chinese男性厕所撒尿合集 | 女人被爽到呻吟娇喘的视频动态图 | 91嫩草私人成人亚洲影院 | 黑人k8经典 | 色综合亚洲天天综合网站 | 欧美日韩国产亚洲一区二区三区 | 精品视频在线免费看 | 91大神大战高跟丝袜美女 | 久久视频这有精品63在线国产 | jj视频免费观看 | 免费观看在线 | 亚洲国产精品第一页 | a级毛片毛片免费观看永久 a级黄色片免费 | 国士李风起全文在线阅读 | 亚洲色图第四页 | 1986葫芦兄弟全集免费观看第十集 | 亚洲精品中文字幕在线 | 黑人干我| 调教车文 | 亚洲国产精品日本无码网站 | 国产亚洲欧美日韩综合综合二区 | 免费一区二区视频 | 99 久久99久久精品免观看 | 成人国产精品视频 | 关晓彤被草| 久久理论片 | 我要看逼 | 成人a级特黄毛片 | 国产精品久久免费 | 欧美一区二区三区精品影视 | 免费黄色小说 |