java迷你DVD管理器
时间: 2023-12-13 08:34:35 浏览: 178
Java迷你DVD管理器是一个基于Java语言开发的DVD管理系统,可以实现DVD的增删改查等基本功能。根据提供的引用内容,可以看出该系统的主要类为DVDMgr和Menu,其中DVDMgr类负责DVD信息的初始化和管理,Menu类负责显示菜单和处理用户输入。下面是一个简单的Java迷你DVD管理器的实现示例:
```java
package com.example.dvd;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* DVD信息类
*/
class DVD {
private String name; // 名称
private String type; // 类型
private String date; // 出版日期
public DVD(String name, String type, String date) {
this.name = name;
this.type = type;
this.date = date;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public String getDate() {
return date;
}
@Override
public String toString() {
return "DVD{" +
"name='" + name + '\'' +
", type='" + type + '\'' +
", date='" + date + '\'' +
'}';
}
}
/**
* DVD管理类
*/
class DVDMgr {
private List<DVD> dvdList = new ArrayList<>();
/**
* 初始化DVD信息
*/
public void initial() {
dvdList.add(new DVD("肖申克的救赎", "剧情", "1994-09-10"));
dvdList.add(new DVD("霸王别姬", "剧情", "1993-01-01"));
dvdList.add(new DVD("阿甘正传", "剧情", "1994-06-23"));
dvdList.add(new DVD("泰坦尼克号", "爱情", "1997-12-19"));
}
/**
* 显示DVD列表
*/
public void showList() {
System.out.println("DVD列表:");
for (int i = 0; i < dvdList.size(); i++) {
System.out.println((i + 1) + ". " + dvdList.get(i));
}
}
/**
* 添加DVD
*/
public void addDVD() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入DVD名称:");
String name = scanner.nextLine();
System.out.print("请输入DVD类型:");
String type = scanner.nextLine();
System.out.print("请输入DVD出版日期(格式:yyyy-MM-dd):");
String date = scanner.nextLine();
dvdList.add(new DVD(name, type, date));
System.out.println("添加成功!");
}
/**
* 删除DVD
*/
public void deleteDVD() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入要删除的DVD编号:");
int index = scanner.nextInt();
if (index < 1 || index > dvdList.size()) {
System.out.println("输入有误!");
return;
}
dvdList.remove(index - 1);
System.out.println("删除成功!");
}
}
/**
* 菜单类
*/
class Menu {
private static final int SHOW_LIST = 1;
private static final int ADD_DVD = 2;
private static final int DELETE_DVD = 3;
private static final int EXIT = 4;
/**
* 显示菜单
*/
public static void showMenu(DVDMgr mgr) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择操作:");
System.out.println("1. 显示DVD列表");
System.out.println("2. 添加DVD");
System.out.println("3. 删除DVD");
System.out.println("4. 退出");
int choice = scanner.nextInt();
switch (choice) {
case SHOW_LIST:
mgr.showList();
break;
case ADD_DVD:
mgr.addDVD();
break;
case DELETE_DVD:
mgr.deleteDVD();
break;
case EXIT:
System.out.println("谢谢使用!");
return;
default:
System.out.println("输入有误,请重新输入!");
break;
}
}
}
}
```
阅读全文