package com.company;
import java.util.Scanner;
/**
* @author dy
* @date 2021/4/9 8:24
*/
public class Librarian {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] bookNames = new String[6];
int[] borrowD = new int[6];
int[] borrowC = new int[6];
int[] states = new int[6];
bookNames[0]="安徒生童话";
borrowD[0] = 15;
borrowC[0] = 16;
states[0] = 0;
bookNames[1]="格林童话";
borrowD[1] = 15;
borrowC[1] = 16;
states[1] = 0;
bookNames[2]="钢铁是怎样炼成的";
borrowD[2] = 15;
borrowC[2] = 16;
states[2] = 0;
int num = -1;
boolean flag = true;
do {
System.out.println("**************欢迎使用Librarian系统*************");
System.out.println("\t\t\t\t\t\t1.新增图书");
System.out.println("\t\t\t\t\t\t2.查看图书");
System.out.println("\t\t\t\t\t\t3.借阅图书");
System.out.println("\t\t\t\t\t\t4.归还图书");
System.out.println("\t\t\t\t\t\t5.删除图书");
System.out.println("\t\t\t\t\t\t6.退出系统");
System.out.println("\n请选择:");
int choose = sc.nextInt();
while (choose<0 || choose>6){
System.out.println("出入错误,请重新输入");
choose = sc.nextInt();
}switch (choose){
case 1:
System.out.println("**********1.新增图书*********");
System.out.println("请输入图书名字");
String addBook = sc.next();
boolean isAdd = false;
for (int i = 1; i <bookNames.length;i++){
if (bookNames[i] == null){
isAdd = true;
bookNames[i] = addBook;
System.out.println("新增成功!");
break;
}else {
isAdd = false;
}
}
for (int i = 0; i<bookNames.length;i++){
if (bookNames[i] !=null){
String state = (states[i]==0)?"可借阅":"已借阅";
String borrowCount = borrowC[i]+"次";
String borrowDate = borrowD[i]+"日";
System.out.println((i+1)+ "\t\t"+bookNames[i]+"\t\t"+state+"\t\t"+borrowC+"\t\t"+borrowD);
}
}
if (!isAdd){
System.out.println("对不起,图书已借出!");
break;
}
break;
case 2:
System.out.println("2.查看图书");
System.out.println("序号" + "\t\t\t" + "书名" + "\t\t\t" + "借阅状态" + "\t\t" + "借阅次数"+ "\t\t" + "借阅日期");
for (int i=0;i<bookNames.length;i++){
if (bookNames[i] !=null){
String state = (states[i]==0)?"可借阅":"已借阅";
String borrowCount = borrowC[i]+"次";
String borrowDate = borrowD[i]+"日";
System.out.println((i+1)+ "\t\t"+bookNames[i]+"\t\t"+state+"\t\t"+borrowC+"\t\t"+borrowD);
}
}break;
case 3:
System.out.println("3.借阅图书");
System.out.println("请输入你要借阅图书的名字:" );
String borrowName = sc.next();
boolean isBorrow = false;
for (int i=0;i< bookNames.length;i++){
if (bookNames[i] != null && bookNames[i].equals(borrowName)&&states[i] ==0){
isBorrow=true;
System.out.println("请输入借阅日期:");
int borrowRiQi=sc.nextInt();
while (borrowRiQi<1 || borrowRiQi>31){
System.out.println("输入错误,请重新输入");
borrowRiQi = sc.nextInt();
}
System.out.println("借阅成功!");
borrowD[i] = borrowRiQi;
states[i] = 1;
borrowC[i]++;
break;
}else if (bookNames[i] !=null && bookNames[i].equals(borrowName) && states[i] ==1){
isBorrow = true;
System.out.println("书已借出,不能重复借阅!");
break;
}
}
if (!isBorrow){
System.out.println("抱歉,找不到该书!");
break;
}break;
case 4:
System.out.println("4.归还图书");
System.out.println("请输入你要归还的图书名字:");
String returnName = sc.next();
boolean isReturn = false;
for (int i=0;i<bookNames.length;i++){
if (bookNames[i] !=null && bookNames[i].equals(returnName) && states[i] == 1){
isReturn = true;
System.out.println("请输入归还日期:");
int returnRiQi = sc.nextInt();
while (returnRiQi<1 || returnRiQi>31 || returnRiQi<borrowD[i]){
if (returnRiQi<1 || returnRiQi >31){
System.out.println("输入错误,请重新输入:");
returnRiQi = sc.nextInt();
}else if(returnRiQi<borrowD[i]){
System.out.println("归还日期必须大于借阅日期,请重新输入:");
returnRiQi=sc.nextInt();
}
}
System.out.println("归还成功!");
states[i]=0;
break;
}else if (bookNames[i] !=null && bookNames[i].equals(returnName) && states[i] == 0){
isBorrow = true;
System.out.println("书可借阅,不能归还!");
break;
}
}
if (!isReturn){
System.out.println("抱歉,不是本图书馆的书,不能归还!");
break;
}
break;
case 5:
System.out.println("5.删除图书");
System.out.print("请输入您要删除图书的名字:");
String deleteName = sc.next();
boolean isDelete = false;
for (int i=0;i<bookNames.length;i++){
if (bookNames[i] !=null && bookNames.equals(deleteName) && states[i] == 1){
isDelete = true;
System.out.println("书已借出,不能删除!");
break;
}else if (bookNames[i] != null && bookNames[i].equals(deleteName) && states[i] == 0){
isDelete = true;
int index = -1;
if(bookNames[i].equals(deleteName)){
index = i;
}
if(index != -1){
for(i = index;i<bookNames.length-1;i++){
bookNames[i] = bookNames[i+1];
borrowD[i] = borrowD[i+1];
borrowC[i] = borrowC[i+1];
states[i] = states[i+1];
bookNames[bookNames.length-1] = null;
borrowD[bookNames.length-1] = 0;
borrowC[bookNames.length-1] = 0;
states[bookNames.length-1] = 0;
}
}
System.out.println("删除图书成功!");
break;
}
}
if(!isDelete){
System.out.println("不是本图书馆的书,不能删除");
break;
}
break;
case 6:
flag = false;
break;
default:
flag = false;
break;
}
if(flag){
System.out.print("\n输入0返回:");
num = sc.nextInt();
}else{
break;
}
}while (flag);
System.out.println("谢谢使用!");
}
}
//这算是一个比较完整的图书管理系统的Java代码,感谢大家的支持与观看!
图书管理系统
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 上节课完成了费用查询功能。 这节课来完成公共图书库存查询功能。 编写图书热门排行榜和库存查询功能 热门排行榜主要是...
- 上节课完成了借书管理功能。 这节课来完成还书管理功能。 编写还书管理功能 还书管理主要是针对数据库表orders进...