用java写一个项目管理系统
时间: 2024-01-01 12:05:51 浏览: 67
抱歉,我是一个语言模型AI,无法编写完整的项目管理系统。但是,我可以为您提供一个简单的项目管理系统的代码框架,您可以在此基础上进行进一步的开发。
```
import java.util.ArrayList;
import java.util.Scanner;
public class ProjectManagementSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Project> projects = new ArrayList<>();
while (true) {
System.out.println("What would you like to do?");
System.out.println("1. Create a new project");
System.out.println("2. List all projects");
System.out.println("3. Edit a project");
System.out.println("4. Delete a project");
System.out.println("5. Exit");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
System.out.println("Enter project name:");
String name = scanner.nextLine();
System.out.println("Enter project description:");
String description = scanner.nextLine();
System.out.println("Enter project deadline (MM/DD/YYYY):");
String deadline = scanner.nextLine();
projects.add(new Project(name, description, deadline));
System.out.println("Project created successfully.");
break;
case 2:
if (projects.isEmpty()) {
System.out.println("No projects found.");
} else {
System.out.println("List of projects:");
for (Project project : projects) {
System.out.println(project);
}
}
break;
case 3:
if (projects.isEmpty()) {
System.out.println("No projects found.");
} else {
System.out.println("Enter project name to edit:");
String projectName = scanner.nextLine();
for (Project project : projects) {
if (project.getName().equals(projectName)) {
System.out.println("Enter new project name:");
String newName = scanner.nextLine();
System.out.println("Enter new project description:");
String newDescription = scanner.nextLine();
System.out.println("Enter new project deadline (MM/DD/YYYY):");
String newDeadline = scanner.nextLine();
project.setName(newName);
project.setDescription(newDescription);
project.setDeadline(newDeadline);
System.out.println("Project edited successfully.");
break;
}
}
}
break;
case 4:
if (projects.isEmpty()) {
System.out.println("No projects found.");
} else {
System.out.println("Enter project name to delete:");
String projectName = scanner.nextLine();
for (Project project : projects) {
if (project.getName().equals(projectName)) {
projects.remove(project);
System.out.println("Project deleted successfully.");
break;
}
}
}
break;
case 5:
System.out.println("Exiting...");
System.exit(0);
break;
default:
System.out.println("Invalid choice.");
}
}
}
}
class Project {
private String name;
private String description;
private String deadline;
public Project(String name, String description, String deadline) {
this.name = name;
this.description = description;
this.deadline = deadline;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDeadline() {
return deadline;
}
public void setDeadline(String deadline) {
this.deadline = deadline;
}
@Override
public String toString() {
return "Name: " + name + "\nDescription: " + description + "\nDeadline: " + deadline + "\n";
}
}
```
该代码框架提供了以下功能:
1. 创建新项目
2. 列出所有项目
3. 编辑项目
4. 删除项目
5. 退出
您可以在此基础上进行进一步的开发,添加更多的功能和自定义的字段。
阅读全文