This exercise focuses on implementing and managing dynamically linked data structures in Java. The primary objective is to create a sorted, singly linked list for Task objects, supporting various operations like adding, clearing, converting to an array, and extracting sublists.
Implement a node class (TaskListNode) to store Task objects and a reference to the next node.
Develop a TaskList class that uses TaskListNode objects and supports the following operations:
-
Add Tasks:
- Method:
void addSorted(Task task) - Adds a
Taskto the list in descending order of duration.
- Method:
-
Clear List:
- Method:
int clear() - Removes all tasks from the list and returns the count of removed tasks.
- Method:
-
Convert to Array:
- Method:
Task[] asArray() - Converts the list into an array representation.
- Method:
-
Extract Sublist:
- Method:
TaskList getTaskListWithin(int minDuration, int maxDuration) - Extracts and returns a new list of tasks within the specified duration range.
- Method:
-
Find Shortest Task:
- Method:
Task getShortestTask() - Returns the task with the shortest duration.
- Method:
-
Find Longest Task:
- Method:
Task getLongestTask() - Returns the task with the longest duration.
- Method:
-
Remove Tasks by Duration:
- Method:
int remove(int duration) - Removes all tasks matching the specified duration and returns the count.
- Method:
-
ToString Representation:
- Method:
String toString() - Returns a string representation of the list, with each task on a new line.
- Method:
-
Static Factory Method:
- Method:
static TaskList from(Task... tasks) - Creates and populates a new
TaskListusing the provided tasks.
- Method:
Develop a TaskListApplication class with a main method to test all functionalities of the TaskList class.
src/
In.javaHelper class for inputOut.javaHelper class for outputTask.javaRepresents a task with a name and durationTaskListNode.javaNode class for the singly linked listTaskList.javaImplementation of the sorted linked list and its operationsTaskListApplication.javaEntry point for testing the list implementation
tests/
Testprotokoll.txtTest cases and results for all tasks
- Programming Language: Java
- Editor: Visual Studio Code with JavaWiz extension
This project is licensed under the MIT License.