请用java编写一个程序实现以下内容,为音像店开发一个迷你DVD管理器实现DVD碟片的管理,包括如下功能::新增DVD,查看DVD,删除DVD,借出DVD,归还DVD

时间: 2023-08-09 07:12:14 浏览: 52
好的,以下是一个简单的迷你DVD管理器的Java代码: ``` import java.util.ArrayList; import java.util.Scanner; public class DVDCollection { private ArrayList<DVD> collection; public DVDCollection() { collection = new ArrayList<DVD>(); } public void addDVD(DVD dvd) { collection.add(dvd); System.out.println(dvd.getTitle() + " 已添加到DVD收藏中。"); } public void viewDVDs() { if (collection.size() == 0) { System.out.println("DVD收藏为空。"); } else { System.out.println("DVD收藏:"); for (int i = 0; i < collection.size(); i++) { System.out.println((i+1) + ". " + collection.get(i).toString()); } } } public void deleteDVD(int index) { if (index < 1 || index > collection.size()) { System.out.println("无效的DVD编号。"); } else { DVD dvd = collection.remove(index-1); System.out.println(dvd.getTitle() + " 已从DVD收藏中删除。"); } } public void borrowDVD(int index) { if (index < 1 || index > collection.size()) { System.out.println("无效的DVD编号。"); } else { DVD dvd = collection.get(index-1); if (dvd.isAvailable()) { dvd.setAvailable(false); System.out.println(dvd.getTitle() + " 已借出。"); } else { System.out.println(dvd.getTitle() + " 已被借出,无法借阅。"); } } } public void returnDVD(int index) { if (index < 1 || index > collection.size()) { System.out.println("无效的DVD编号。"); } else { DVD dvd = collection.get(index-1); if (!dvd.isAvailable()) { dvd.setAvailable(true); System.out.println(dvd.getTitle() + " 已归还。"); } else { System.out.println(dvd.getTitle() + " 已经在DVD收藏中,无需归还。"); } } } public static void main(String[] args) { DVDCollection dvdCollection = new DVDCollection(); Scanner input = new Scanner(System.in); while (true) { System.out.println("\n请选择操作:\n1. 新增DVD\n2. 查看DVD\n3. 删除DVD\n4. 借出DVD\n5. 归还DVD\n6. 退出"); int choice = input.nextInt(); switch (choice) { case 1: System.out.print("请输入DVD标题:"); input.nextLine(); String title = input.nextLine(); System.out.print("请输入DVD类型:"); String type = input.nextLine(); DVD dvd = new DVD(title, type); dvdCollection.addDVD(dvd); break; case 2: dvdCollection.viewDVDs(); break; case 3: System.out.print("请输入要删除的DVD编号:"); int indexToDelete = input.nextInt(); dvdCollection.deleteDVD(indexToDelete); break; case 4: System.out.print("请输入要借出的DVD编号:"); int indexToBorrow = input.nextInt(); dvdCollection.borrowDVD(indexToBorrow); break; case 5: System.out.print("请输入要归还的DVD编号:"); int indexToReturn = input.nextInt(); dvdCollection.returnDVD(indexToReturn); break; case 6: System.out.println("谢谢使用DVD管理器。"); System.exit(0); break; default: System.out.println("无效的选项。"); break; } } } } class DVD { private String title; private String type; private boolean available; public DVD(String title, String type) { this.title = title; this.type = type; this.available = true; } public String getTitle() { return title; } public String getType() { return type; } public boolean isAvailable() { return available; } public void setAvailable(boolean available) { this.available = available; } public String toString() { String status = available ? "可借" : "不可借"; return title + " (" + type + ") - " + status; } } ``` 这个程序使用了ArrayList来存储DVD对象,并提供了新增、查看、删除、借出和归还DVD的功能。DVD类包含了标题、类型和可用性状态等属性,并提供了相应的get和set方法。在主函数中,我们使用了一个简单的用户界面来展示DVD管理器的功能,并使用switch语句来处理用户输入的操作。

相关推荐

最新推荐

recommend-type

基于java的影碟租售管理系统的设计与实现

本文主要研究影碟租赁管理系统的设计与实现,使用java语言和MySQL数据库技术开发而成,它是基于MVC模式的Struts框架,具有组件的模块化,灵活性和重用性的优点。系统功能主要有影碟租借、归还、用户注册登陆、管理员...
recommend-type

音像租赁管理系统数据库报告

本系统主要实现的是音像租赁的管理操作,其主要的实现的功能是,光盘租赁管理、光盘信息管理、帐目结算、系统用户设置、会员信息管理等。
recommend-type

网上音像店毕业设计论文

网上音像店系统是一个电子商务系统,并以ASP.NET和SQL Server数据库作为开发平台。使用ASP.NET设计操作控件和编写操作程序,完成数据输入、修改、存储、调用查询等功能;并使用SQL Server数据库形成数据表,进行数据...
recommend-type

数据库课程设计—俊丽音像品店出租及销售管理系统

1. 概述(设计题目与可行性分析) 2. 系统目标和设计原则 3. 支撑环境规划 4. 系统功能结构 5. 数据库设计 6. 总体实施计划 7. 总结 8. 参考文献
recommend-type

课程设计音像租赁商店管理系统需求分析报告

音像租赁商店管理系统的需求情况,包括系统总体要求,各个子系统的功能要求等,旨在为系统的设计开发提供参考依据,确保系统的分析无歧义
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用 Python 画一个可以动的爱心

好的,我可以帮助您使用Python来绘制一个动态的爱心。您可以使用turtle库来实现。以下是实现代码: ```python import turtle import math # 设置画布和画笔 canvas = turtle.Screen() canvas.bgcolor("black") pencil = turtle.Turtle() pencil.speed(0) pencil.color("red", "pink") pencil.pensize(3) # 定义爱心函数 def draw_love(heart_size, x_offset=0, y_offset=0):
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。