图书馆系统简单版
import java.util.Scanner;
public class LibraryManagement {
static Scanner input = new Scanner(System.in);
static int len = 10;
static String[] id = new String[len];
static String[] name = new String[len];
static String[] author = new String[len];
static String[] time = new String[len];
static String[] press = new String[len];
static Double[] price = new Double[len];
static boolean[] state = new boolean[len];
static String[] comment = new String[len];
static int num = 0;
public static void main(String[] args) {
while(true){
Show();
}
}
public static void Show(){
System.out.println("-------------------------");
System.out.println("\t1、图书上架(信息录入)");
System.out.println("\t2、图书信息的修改");
System.out.println("\t3、图书下架(删除)");
System.out.println("\t4、借书");
System.out.println("\t5、还书");
System.out.println("\t6、图书信息的查看");
System.out.println("\t7、查看所有图书");
System.out.println("\t0、退出系统");
System.out.println("-------------------------");
System.out.println("请输入选择功能:");
int option = input.nextInt();
switch(option){
case 1:
AddBook();
break;
case 2:
System.out.print("请输入需要修改信息图书的ID:");
ReviseBook();
break;
case 3:
System.out.println("请输入需要删除图书信息的id");
DeleteBook();
break;
case 4:
System.out.println("请输入需要借阅书籍的ID:");
BorrowBook();
break;
case 5:
System.out.println("请输入需要归还书籍的ID:");
ReturnBook();
break;
case 6:
System.out.println("请输入需要查看图书信息的id");
FindBook();
break;
case 7:
FindAllBook();
break;
case 0:
System.exit(1);
default:
System.out.println("不好意思,您输入有误,请重新输入!");
}
}
public static void AddBook(){
System.out.println("请输入书籍编号:");
id[num] = input.next();
System.out.println("请输入书名:");
name[num] = input.next();
System.out.println("请输入书籍作者:");
author[num] = input.next();
System.out.println("请输入出版时间:");
time[num] = input.next();
System.out.println("请输入出版社:");
press[num] = input.next();
System.out.println("请输入价格:");
price[num] = input.nextDouble();
state[num] = true ;
comment[num] = "空闲";
num++;
}
public static void ReviseBook(){
int i = GetBooknum();
if(i != -1){
System.out.println("请确认是否选择修改ID为 " + id[i] +" 的书");
ShowBook(i);
System.out.println();
while(true) {
System.out.println("确认修改,请输入 1 ;取消修改,请输入 2");
int j = input.nextInt();
switch(j) {
case 1:
System.out.println("请输入修改后的书名:");
name[i] = input.next();
System.out.println("请输入修改后的作者:");
author[i] = input.next();
System.out.println("请输入修改后的出版时间:");
time[i] = input.next();
System.out.println("请输入修改后的出版社:");
press[i] = input.next();
System.out.println("请输入修改后的价格:");
price[i] = input.nextDouble();
System.out.println("*** 修改成功!***");
return;
case 2:
System.out.println("*** 该图书没有被修改 ***");
return;
default:
System.out.println("*** 输入有误,请重新输入 ***");
}
}
}
}
public static void DeleteBook(){
int i = GetBooknum();
if(i != -1){
System.out.println("请确认是否选择删除ID为 " + id[i] +" 的书");
ShowBook(i);
System.out.println();
while(true) {
System.out.println("确认删除,请输入 1 ;取消删除,请输入 2");
int j = input.nextInt();
switch (j) {
case 1:
id[i] = id[num - 1];
name[i] = name[num - 1];
author[i] = author[num - 1];
time[i] = time[num - 1];
press[i] = press[num - 1];
price[i] = price[num - 1];
state[i] = state[num - 1];
comment[i] = comment[num - 1];
num--;
System.out.println("*** 删除成功!***");
return;
case 2:
System.out.println("*** 该图书没有被删除 ***");
return;
default:
System.out.println("*** 输入有误,请重新输入 ***");
}
}
}
}
public static void BorrowBook(){
int i = GetBooknum();
if(state[i]){
System.out.println("请输入您的姓名:");
comment[i] = input.next();
System.out.println("*** 借阅成功! ***");
state[i] = false;
}else{
System.out.println("*** 借阅失败! ***");
System.out.println("该图书已被借走,借阅人是:" + comment[i]);
}
}
public static void ReturnBook(){
int i = GetBooknum();
while(true){
if(state[i]){
System.out.println("输入有误,该图书当前未被借阅!");
return;
}else{
state[i] = !state[i];
comment[i] = "空闲";
System.out.println("归还成功");
return;
}
}
}
public static void FindBook(){
int i = GetBooknum();
if(i != -1){
ShowBook(i);
}
System.out.println();
}
public static void FindAllBook(){
if(num == 0){
System.out.println("暂时没有图书!");
}else{
for(int i = 0 ; i < num ; i++){
ShowBook(i);
System.out.println();
}
}
}
public static int GetBooknum(){
String id1 = input.next();
for(int i = 0 ; i < num ; i++) {
if (id1.equals(id[i])) {
return i;
}
}
System.out.println("没有这本书!");
return -1;
}
public static void ShowBook(int i){
System.out.println("书籍ID:" +id[i]);
System.out.print("书名:" +name[i]+" ");
System.out.print("书籍作者:" +author[i]+" ");
System.out.print("出版时间:" +time[i]+" ");
System.out.print("出版社:" +press[i]+" ");
System.out.print("价格:" +price[i]+" ");
System.out.print("书籍没有被借出:"+state[i]+" ");
System.out.print("备注:" +comment[i]+" ");
}
}