首页>代码>java控制台图书管理系统>/图书管理系统/图书管理/BookTest.java
package music;
import java.util.Scanner;
public class BookTest {
	static class BookSet {//创建数组用的类set对象
		int[] id = new int[5];// 序号
		String[] name = new String[5];// Book名字
		String[] state = new String[5];// Book状态
		String[] time = new String[5]; // 图书借出日期
		int[] count = new int[5];// 记录被借出次数,用于排行榜中
	}
	static class BookFunction {
		Scanner sc = new Scanner(System.in);
		BookSet set = new BookSet();// 实例化BookSet类
		// 主界面 show()方法
		public void show() {
			System.out.println("欢  迎  来 到  图   书  管  理  系    统");
			System.out.println("-----------------------");
			System.out.println("1.  新 增 Book 信息");
			System.out.println("2.  查 看 Book 信息");
			System.out.println("3.  借 出 Book");
			System.out.println("0.  退          出");
			System.out.println("-----------------------");
		}
		// 添加Book add()方法
		public void add(String BookName) {
			// 找到第一个为空的数组,将新增的Book添加进去
			int i;
			for (i = 0; i < set.name.length; i++) {//下标数组为0 的 
				if (set.name[0] == null) {// 成功添加
					set.name[i] = BookName;
					set.id[0] = i;
					set.state[i] = "可借";
					set.time[i] = "  ";
					set.count[i] = 0;
					System.out.println("新增书籍名称为:《" + BookName + "》成功!");
					System.out.println("*********************");
					break;
				}
			}}
		// 查看Book examine()方法
		public void query() {
			System.out.println("序号\t状态\t名称\t借出日期");
			// 将Book循环输出
			for (int i = 0; i < set.name.length; i++) {
				if (set.name[i] != null) {
					System.out.println((set.id[i] + 1) + "\t" + set.state[i] + "\t《" + set.name[i] + "》\t" + set.time[i]);
				}
			}
			System.out.println("*********************");
		}
		// 借出Book borrow()方法
		public void borrow(String BookName) {
			int i;
			for (i = 0; i < set.name.length; i++) {
				if (set.name[i] != null && set.name[i].equals(BookName)) {
					if (set.state[i].equals("可借")) {
						set.state[i] = "借出";// 标记借书状态为 已借出
						set.count[i]++;
						System.out.print("请输入借出日期(年-月-日):");
						set.time[i] = sc.next();
						System.out.println("借出图书《" + set.name[i] + "》成功!");
						System.out.println("*********************");
						break;
					} else {
						System.out.println("《" + set.name[i] + "》为借出状态!");
						break;
					}
				}
			}
			if (i == set.name.length) {
				System.out.println("没有找到:" + BookName + "!");
				System.out.println("*********************");
			}
		}

		
	}
	public static void main(String[] args) {
		BookFunction book = new BookFunction();// 实例化Book功能类
		Scanner sc = new Scanner(System.in);
		do {
			book.show();// 调用主界面
			System.out.print("请选择:");
			switch (sc.next()) {
			case "1":// 增加Book的选择
				System.out.println("--->新增Book");
				System.out.print("请输入   Book 名称:");
				   String a= sc.next();
				   book.add(a);// 调用增加Book的方法
				break;
			case "2":// 查看Book的选择
				System.out.println("--->查看Book");
				book.query();
				break;

			case "3":// 借出Book的选择
				System.out.println("--->借出Book");
				System.out.print("请输入Book名称:");
				book.borrow(sc.next());
				break;
			case "0":// 退出系统
				System.out.println("谢谢使用!");
				break;
			default:
				System.out.println("输入有误!");
				break;
			}
		} while (true);
	}

}

最近下载更多
ash99919  LV1 2024年5月31日
xiaoyu111ewsd  LV4 2024年1月7日
wiehwhfe  LV1 2024年1月1日
768881787  LV7 2023年12月21日
huangtian  LV3 2023年6月24日
yishiren  LV2 2023年6月19日
微信网友_6497761417269248  LV1 2023年5月30日
于先森  LV1 2023年5月30日
VEVOPP  LV2 2023年5月29日
15342201772  LV9 2022年12月4日
最近浏览更多
千千万万呃呃 4月10日
暂无贡献等级
鲁一宇  LV5 2024年12月23日
wyaolo1 2024年12月23日
暂无贡献等级
yuanshun  LV7 2024年12月10日
Cathy123 2024年12月1日
暂无贡献等级
18611979082 2024年11月28日
暂无贡献等级
南一明华 2024年11月22日
暂无贡献等级
momomo228  LV2 2024年11月21日
52slyxy 2024年10月20日
暂无贡献等级
ljxwwefhj 2024年10月18日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友