图书管理系统(Java一阶)
作者:互联网
图书管理系统
1.添加图书
2.查看图书
3.删除图书
4.借阅图书
5.归还图书
6.查找图书
0.退出系统
public class LibrarySystem {
public static void main(String[] args) {
int[] number = {1,2,3,4,5};//书籍编号
String[] name = {"数电","模电","计算机基础","",""};//书名
String[] state = {"未借出","已借出","已借出","",""};//借阅状态
int[] days = {0,1,2,0,0};//借阅天数
int[] times = {3,4,5,0,0};//借阅次数
String state1 = "已借出";//状态1
String state2 = "未借出";//状态2
int length = name.length;//定义长度
out:
for(;;){
//系统界面
System.out.println("----------图书管理系统----------");
System.out.println("----------1. 添加图书----------");
System.out.println("----------2. 查看图书----------");
System.out.println("----------3. 删除图书----------");
System.out.println("----------4. 借阅图书----------");
System.out.println("----------5. 归还图书----------");
System.out.println("----------6. 查找图书----------");
System.out.println("----------0. 退出系统----------");
System.out.println("请输入0——6!");
//创建输入对象
Scanner impute = new Scanner(System.in);
String num = impute.next();
switch (num) {
case "1"://1.添加
for (int i = 0;;i++) {
//如果i等于数组的长度,输出“书库已满”并返回菜单
if(i==length) {
System.out.println("书库已满!");
continue out;
}
//如果名字等于空,开始录入信息
if (name[i].equals("")) {
System.out.print("请输入你想要添加的书名:");
Scanner impute1 = new Scanner(System.in);
String name1 = impute1.next();
number[i] = i + 1;
name[i] = name1;
state[i] = state2;
days[i] = 0;
times[i] = 0;
System.out.println("添加成功!");
continue out;
}
}
case "2"://2.查看
System.out.println("编号\t书名\t\t借阅状态\t借阅天数\t借出次数");//输出标题
//遍历数组信息
for(int i = 0;i<length;i++){
//在书名为空时停止输出
if(name[i].equals("")){
continue out;
}else{
System.out.println(number[i]+"\t"+name[i]+"\t\t"+state[i]+"\t\t"+days[i]+"\t\t"+times[i]);
}
}
case "3"://3.删除
System.out.print("请输入你想要删除的书名:");
//创建输入对象
Scanner impute1 = new Scanner(System.in);
String name1 = impute1.next();
for(int i = 0;i<length;i++){
if(name[i].equals(name1)){
for (int j = i;j<length-1;j++){
name[j] = name[j+1];
state[j] = state[j+1];
days[j] = days[j+1];
times[j] = times[j+1];
}
name[length-1] = "";
state[length-1] = "";
days[length-1] = 0;
times[length-1] = 0;
System.out.println("删除成功!");
continue out;
}
if(i==length-1){
System.out.println("查无此书!请重新输入!");
System.out.print("请输入你想要删除的书名:");
//创建输入对象
Scanner impute2 = new Scanner(System.in);
name1 = impute2.next();
i = 0;
}
}
case "4"://4.借阅
System.out.print("请输入借阅的书名:");
Scanner impute4 = new Scanner(System.in);
String name4 = impute4.next();
for(int i = 0;;i++){
if(i==length){
System.out.println("查无此书!");
continue out;
}
if(name[i].equals(name4)){
if(state[i].equals(state1)){
System.out.println("此书已借出!");
}else{
System.out.print("请输入借阅天数:");
Scanner impute3 = new Scanner(System.in);
int day1 = impute3.nextInt();
state[i] = state1;
days[i] = day1;
times[i]++;
System.out.println("书籍已经成功借出!");
}
continue out;
}
}
case "5"://5.归还
System.out.print("请输入归还的书名:");
Scanner impute5 = new Scanner(System.in);
String name5 = impute5.next();
for(int i = 0;;i++){
if(i==length){
System.out.println("查无此书!请重新输入!");
System.out.print("请输入归还的书名:");
Scanner impute2 = new Scanner(System.in);
name5 = impute2.next();
i = 0;
}
if(name[i].equals(name5)){
state[i] = state2;
days[i] = 0;
System.out.println("书籍已经成功归还!");
continue out;
}
}
case "6"://6.查找
System.out.print("请输入查找的书名:");
Scanner impute6 = new Scanner(System.in);
String name6 = impute6.next();
for(int i = 0;;i++){
if(i==length){
System.out.println("查无此书!");
continue out;
}
if(name[i].equals(name6)){
System.out.println("编号\t书名\t\t借阅状态\t借阅天数\t借出次数");
System.out.println((i+1)+"\t"+name[i]+"\t\t"+state[i]+"\t\t"+days[i]+"\t\t"+times[i]);
continue out;
}
}
case "0"://0.退出系统
System.out.println("感谢使用!");
break out;
default://输入错误
System.out.println("输入错误!请重新输入!");
}
}
}
}
标签:Java,String,管理系统,System,println,一阶,----------,图书,out 来源: https://blog.csdn.net/lanxiaoDo/article/details/110358225