基于数组,编写一个迷你DVD碟片租赁系统。

功能包括:
新增DVD、删除DVD、修改DVD、查看DVD、借出DVD、归还DVD、退出系统

效果图大概如下图所示:

代码如下:

package com.cx1;

import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;



public class Homework1 {
/*
 * 基于数组,编写一个迷你DVD碟片租赁系统。
功能包括:
新增DVD、删除DVD、修改DVD、查看DVD、借出DVD、归还DVD、退出系统
 */
	static Scanner scanner = new Scanner(System.in);
	
	static String []dvdName;
	static int []dvdPrice;
	static int []dvdStatus; //0-未借出, 1-已借出
	static String []dvdDate;
	
	public static void main(String[] args) {

		/*
		 * 开发一个迷你DVD租赁系统
		 * 提供功能:
		 * 新增、删除、修改、查看DVD
		 * 接触、归还DVD、退出系统
		 */
		init();
		
		do {	
		System.out.println("====欢迎使用迷你DVD管理器====");
		System.out.println("1.新增DVD");
		System.out.println("2.删除DVD");
		System.out.println("3.修改DVD");
		System.out.println("4.查看DVD");
		System.out.println("5.借出DVD");
		System.out.println("6.归还DVD");
		System.out.println("7.退出系统");
		System.out.println("==========================");
		System.out.println("请选择:");
		String choose = scanner.next();
		switch(choose) {
		case "1":
			addDVD();
			break;
		case "2":
			deleteDVD();
			break;
		case "3":
			upDateDVD();
			break;
		case "4":
			queryDVD();
			break;
		case "5":
			loanDVD();
			break;
		case "6":
			backDVD();
			break;
		case "7":
			System.out.p
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的迷你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语句来处理用户输入的操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值