In this article, we explore the design and implementation of a Task Management System using Java, with a focus on object-oriented principles.
The system allows users to create, manage, and track tasks effectively.
The Task Management System should:
- Task Creation and Management: Enable users to create, update, and delete tasks.
- User Management: Manage user accounts and associated tasks.
- Task Assignment: Allow tasks to be assigned to specific users.
- Task Tracking: Track the progress and status of tasks.
- Notifications: Notify users about task deadlines and updates.
- Managing User Accounts
- Creating and Updating Tasks
- Assigning Tasks to Users
- Tracking Task Progress
- Sending Notifications
TaskManagementSystem
: Manages the overall system.User
: Represents a system user.Task
: Represents a task.TaskStatus
: Enum for task status.
Manages user account information.
import java.util.ArrayList;
import java.util.List;
public class User {
private String userId;
private String name;
private List<Task> assignedTasks;
public User(String userId, String name) {
this.userId = userId;
this.name = name;
this.assignedTasks = new ArrayList<>();
}
public void addTask(Task task) {
assignedTasks.add(task);
}
// Getters and setters...
}
Represents a task.
import java.util.Date;
public class Task {
private String taskId;
private String title;
private String description;
private Date dueDate;
private TaskStatus status;
public Task(String taskId, String title, Date dueDate) {
this.taskId = taskId;
this.title = title;
this.dueDate = dueDate;
this.status = TaskStatus.PENDING;
}
public void updateStatus(TaskStatus newStatus) {
this.status = newStatus;
}
// Getters and setters...
}
enum TaskStatus {
PENDING, IN_PROGRESS, COMPLETED, CANCELLED
}
Manages task management operations.
import java.util.ArrayList;
import java.util.List;
public class TaskManagementSystem {
private List<User> users;
private List<Task> tasks;
public TaskManagementSystem() {
this.users = new ArrayList<>();
this.tasks = new ArrayList<>();
}
public void addUser(User user) {
users.add(user);
}
public void addTask(Task task) {
tasks.add(task);
}
public void assignTaskToUser(String taskId, String userId) {
User user = findUserById(userId);
Task task = findTaskById(taskId);
if (user != null && task != null) {
user.addTask(task);
}
}
public User findUserById(String userId) {
for (User user : users) {
if (user.getUserId().equals(userId)) {
return user;
}
}
return null;
}
public Task findTaskById(String taskId) {
for (Task task : tasks) {
if (task.getTaskId().equals(taskId)) {
return task;
}
}
return null;
}