package moni; import java.util.Scanner; public class DVDTest { static class DVDSet { int[] no = new int[50];// 序号 String[] name = new String[50];// DVD名字 String[] state = new String[50];// DVD状态 String[] time = new String[50]; // 借出日期 int[] count = new int[50];// 记录被借出次数,用于排行榜中 } static class DVDFunction { Scanner sc = new Scanner(System.in); DVDSet set = new DVDSet();// 实例化DVDSet类 // 主界面 show()方法 public void show() { System.out.println("欢 迎 使 用 迷 你 DVD 管 理 器"); System.out.println("-----------------------"); System.out.println("1. 新 增 DVD"); System.out.println("2. 查 看 DVD"); System.out.println("4. 借 出 DVD"); // System.out.println("5. 归 还 DVD"); System.out.println("6. 退 出"); System.out.println("-----------------------"); } // 添加DVD add()方法 public void add(String DVDName) { // 找到第一个为空的数组,将新增的DVD添加进去 int i; for (i = 0; i < set.name.length; i++) { if (set.name[i] == null) {// 成功添加 set.name[i] = DVDName; set.no[i] = i; set.state[i] = "可借"; set.time[i] = " "; set.count[i] = 0; System.out.println("新增《" + DVDName + "》成功!"); System.out.println("*********************"); break; } }} // 查看DVD examine()方法 public void examine() { System.out.println("序号\t状态\t名称\t借出日期"); // 将DVD循环输出 for (int i = 0; i < set.name.length; i++) { if (set.name[i] != null) { System.out.println((set.no[i] + 1) + "\t" + set.state[i] + "\t《" + set.name[i] + "》\t" + set.time[i]); } } System.out.println("*********************"); } // 借出DVD borrow()方法 public void borrow(String DVDName) { int i; for (i = 0; i < set.name.length; i++) { if (set.name[i] != null && set.name[i].equals(DVDName)) { 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("没有找到:" + DVDName + "!"); System.out.println("*********************"); } } // 退出系统 exit()方法 public void exit() { System.out.println("谢谢使用!"); } } public static void main(String[] args) { int[] no = new int[50];// 序号 String[] name = new String[50];// DVD名字 String[] state = new String[50];// DVD状态 String[] time = new String[50]; // 借出日期 DVDFunction dvd = new DVDFunction();// 实例化dvd功能类 Scanner sc = new Scanner(System.in); boolean isGoon = false;// 判断返回主菜单的选择是否正确 boolean isCon = true;// 判断返回上一级菜单的选择是否输入正确 boolean isSon = true; do { isGoon = false;// 初始化 isCon = true; isSon = true; dvd.show();// 调用主界面 System.out.print("请选择:"); switch (sc.next()) { case "1":// 增加DVD的选择 System.out.println("--->新增DVD"); System.out.print("请输入 DVD 名称:"); String a= sc.next(); dvd.add(a);// 调用增加DVD的方法 break; case "2":// 查看DVD的选择 System.out.println("--->查看DVD"); dvd.examine(); break; case "4":// 借出DVD的选择 System.out.println("--->借出DVD"); System.out.print("请输入DVD名称:"); dvd.borrow(sc.next()); break; case "6":// 退出系统 dvd.exit(); isCon = false; break; default: System.out.println("输入有误!"); break; } while (isCon) { System.out.print("\n输入0返回:"); if (sc.nextInt() == 0) { isCon = false;// 返回上一级菜单输入正确 isGoon = true; } else { System.out.println("输入有误,重新输入"); isCon = true;// 返回上一级菜单输入错误 } } } while (isGoon); } }

KAIzx11 LV8
2022年12月21日
姜广坤 LV14
2022年11月10日
wanglinddad LV55
2022年5月31日
谦恭有礼陈大器 LV1
2022年4月13日
1265260263 LV4
2022年4月8日
13112360 LV2
2022年1月10日
最代码-宋家辉 LV61
2021年12月17日
j剑不合鞘 LV1
2021年12月10日
Demo1111 LV30
2021年12月6日
最代码官方 LV168
2021年7月24日

yuanshun LV7
2024年12月10日
java 0小白
2024年11月29日
暂无贡献等级
yimaoermao LV1
2024年11月28日
taoshen95 LV16
2024年1月5日
mengh1 LV1
2024年1月3日
Kaiaahh LV2
2023年12月30日
刘liuliu LV1
2023年11月12日
Ji123455 LV8
2023年9月21日
tth121935193 LV14
2023年9月13日
fwebblAewu4y3
2023年6月26日
暂无贡献等级