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
Task
to 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
TaskList
using the provided tasks.
- Method:
Develop a TaskListApplication
class with a main
method to test all functionalities of the TaskList
class.
src/
In.java
Helper class for inputOut.java
Helper class for outputTask.java
Represents a task with a name and durationTaskListNode.java
Node class for the singly linked listTaskList.java
Implementation of the sorted linked list and its operationsTaskListApplication.java
Entry point for testing the list implementation
tests/
Testprotokoll.txt
Test cases and results for all tasks
- Programming Language: Java
- Editor: Visual Studio Code with JavaWiz extension
This project is licensed under the MIT License.