用Java创建一个DVD管理系统
时间: 2023-05-12 18:04:43 浏览: 72
好的,我可以为您提供一个基本的DVD管理系统的Java代码,您可以根据自己的需求进行修改和扩展:
```
import java.util.ArrayList;
import java.util.Scanner;
public class DVDManagementSystem {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
ArrayList<DVD> dvdList = new ArrayList<DVD>();
int choice = 0;
do {
System.out.println("1. Add DVD");
System.out.println("2. Remove DVD");
System.out.println("3. Display all DVDs");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
choice = input.nextInt();
switch (choice) {
case 1:
System.out.print("Enter DVD title: ");
String title = input.next();
System.out.print("Enter DVD director: ");
String director = input.next();
System.out.print("Enter DVD release year: ");
int year = input.nextInt();
DVD dvd = new DVD(title, director, year);
dvdList.add(dvd);
System.out.println("DVD added successfully!");
break;
case 2:
System.out.print("Enter DVD title to remove: ");
String titleToRemove = input.next();
boolean removed = false;
for (int i = 0; i < dvdList.size(); i++) {
if (dvdList.get(i).getTitle().equals(titleToRemove)) {
dvdList.remove(i);
removed = true;
break;
}
}
if (removed) {
System.out.println("DVD removed successfully!");
} else {
System.out.println("DVD not found!");
}
break;
case 3:
System.out.println("DVDs in the system:");
for (DVD d : dvdList) {
System.out.println(d);
}
break;
case 4:
System.out.println("Exiting DVD management system...");
break;
default:
System.out.println("Invalid choice!");
break;
}
} while (choice != 4);
}
}
class DVD {
private String title;
private String director;
private int releaseYear;
public DVD(String title, String director, int releaseYear) {
this.title = title;
this.director = director;
this.releaseYear = releaseYear;
}
public String getTitle() {
return title;
}
public String getDirector() {
return director;
}
public int getReleaseYear() {
return releaseYear;
}
public String toString() {
return "Title: " + title + ", Director: " + director + ", Release Year: " + releaseYear;
}
}
```
希望这个代码对您有所帮助!
相关推荐
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)