This sprint challenge will test your understanding of object-oriented programming concepts in Java, including classes, objects, access modifiers, class design principles, boolean logic, enums, and exception handling.
Your sprint challenge is to implement a Task Management System with the following components:
Create a Task class with appropriate instance variables, constructors, and methods:
Create an enum to represent different task statuses:
Create an enum to represent task priorities:
Create custom exception classes for your application:
Create a TaskManager class to manage a collection of tasks:
public class Task { private String id; private String title; private String description; private LocalDate dueDate; private TaskStatus status; private TaskPriority priority; // Constructors public Task(String title) { this(title, "", LocalDate.now().plusDays(7), TaskPriority.MEDIUM); } public Task(String title, String description, LocalDate dueDate, TaskPriority priority) { this.id = UUID.randomUUID().toString(); this.title = title; this.description = description; this.dueDate = dueDate; this.status = TaskStatus.NOT_STARTED; this.priority = priority; } // Getters and setters with validation public String getTitle() { return title; } public void setTitle(String title) { if (title == null || title.trim().isEmpty()) { throw new IllegalArgumentException("Title cannot be empty"); } this.title = title; } // Other methods public boolean isOverdue() { return LocalDate.now().isAfter(dueDate) && status != TaskStatus.COMPLETED; } public void markComplete() { this.status = TaskStatus.COMPLETED; } }
public enum TaskStatus { NOT_STARTED("Not Started"), IN_PROGRESS("In Progress"), COMPLETED("Completed"), CANCELLED("Cancelled"); private final String displayName; TaskStatus(String displayName) { this.displayName = displayName; } public String getDisplayName() { return displayName; } } public enum TaskPriority { LOW(1), MEDIUM(2), HIGH(3), URGENT(4); private final int level; TaskPriority(int level) { this.level = level; } public int getLevel() { return level; } public boolean isHigherThan(TaskPriority other) { return this.level > other.level; } }
// Custom exception public class TaskNotFoundException extends Exception { public TaskNotFoundException(String taskId) { super("Task not found with ID: " + taskId); } } // Using in TaskManager public class TaskManager { private Listtasks = new ArrayList<>(); public Task findTaskById(String id) throws TaskNotFoundException { for (Task task : tasks) { if (task.getId().equals(id)) { return task; } } throw new TaskNotFoundException(id); } public void updateTaskTitle(String id, String newTitle) throws TaskNotFoundException { Task task = findTaskById(id); try { task.setTitle(newTitle); } catch (IllegalArgumentException e) { System.err.println("Failed to update task: " + e.getMessage()); } } }
For this sprint challenge, you will continue working with your existing repository from the previous sprint:
You will need to demonstrate your understanding of:
To submit your sprint challenge:
Important: Make sure to maintain a clean commit history and document your changes in the README.md file.
If you need assistance during the sprint challenge: