← Back to Home

Sprint Challenge: Object-Oriented Programming in Java

Challenge Overview

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.

Learning Objectives Assessed

Module 1: Classes, Objects, and Access

  • Define instance variables to store the internal state of an object
  • Implement a class with multiple constructors to allow optional constructor arguments
  • Explain the relationship between a class and an object
  • Implement code to instantiate an object by calling a constructor with and without parameters
  • Explain the scope of visibility of a class's public and private member variables
  • Implement instance methods that read and modify instance variables

Module 2: Class Design

  • Implement a set of classes that translate a class diagram containing composition, instance variables, constructors and methods into code
  • Compare and contrast private against public access
  • Decide which access modifiers to use when implementing a class, its member variables and methods

Module 3: Boolean Logic and Enums

  • Calculate and use boolean expressions in conditional logic
  • Implement compound boolean expressions with short-circuiting
  • Use the equals method to compare objects
  • Implement enum types to represent sets of predefined constants
  • Use defined enum types in your code

Module 4: Exceptions

  • Implement code that throws an exception when a method input is invalid
  • Handle NullPointerException and other runtime exceptions appropriately

Challenge Requirements

Your sprint challenge is to implement a Task Management System with the following components:

1. Task Class

Create a Task class with appropriate instance variables, constructors, and methods:

  • Instance variables for task details (id, title, description, dueDate, etc.)
  • Multiple constructors with different parameter options
  • Getter and setter methods with appropriate validation
  • Methods to mark tasks as complete, overdue, etc.

2. TaskStatus Enum

Create an enum to represent different task statuses:

  • Define statuses like NOT_STARTED, IN_PROGRESS, COMPLETED, CANCELLED
  • Add appropriate properties and methods to the enum

3. Task Priority Enum

Create an enum to represent task priorities:

  • Define priorities like LOW, MEDIUM, HIGH, URGENT
  • Include methods to compare priorities

4. Custom Exception Classes

Create custom exception classes for your application:

  • TaskNotFoundException
  • InvalidTaskException

5. TaskManager Class

Create a TaskManager class to manage a collection of tasks:

  • Methods to add, remove, and find tasks
  • Methods to filter tasks by status, priority, due date, etc.
  • Proper exception handling for invalid inputs and edge cases

Code Quality Requirements

  • Proper encapsulation of instance variables (use appropriate access modifiers)
  • Comprehensive validation of method inputs
  • Consistent and descriptive variable and method naming
  • Clear exception handling with informative error messages
  • Javadoc comments for classes and methods

Implementation Guidance

Task Class Example

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;
    }
}
                

Enum Examples

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;
    }
}
                

Exception Handling Example

// 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 List tasks = 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());
        }
    }
}
                

Getting Started

Repository Setup

For this sprint challenge, you will continue working with your existing repository from the previous sprint:

  • Use your existing repository: Continue working in the repository you created for the previous sprint challenge
  • Add new features: You will be adding new functionality to your existing codebase
  • Maintain existing code: Make sure to preserve and build upon your previous work

Challenge Requirements

You will need to demonstrate your understanding of:

  • Java classes and objects
  • Access modifiers and encapsulation
  • Class design principles
  • Boolean logic and conditionals
  • Enumerated types
  • Exception handling

Implementation Steps

  1. Review your existing codebase and identify areas for improvement
  2. Implement new features using the concepts learned in this sprint
  3. Add appropriate exception handling to your code
  4. Use enums where appropriate for type safety
  5. Apply class design principles to improve your code structure
  6. Write and execute test cases for new functionality
  7. Document your changes and improvements

Submission Guidelines

To submit your sprint challenge:

  1. Ensure all your changes are committed to your repository
  2. Push your changes to GitHub
  3. Submit your repository URL through the submission form
  4. Complete the sprint reflection form

Important: Make sure to maintain a clean commit history and document your changes in the README.md file.

Need Help?

If you need assistance during the sprint challenge:

  • Review the module materials and documentation
  • Consult with your team lead or instructor
  • Use the course discussion forums
  • Check the additional resources provided in each module