Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e0bee06
First test
Jan 9, 2025
13a72c6
Easiest possible way to pass task1
Jan 9, 2025
e246d32
new test for task1 that will fail at the moment
Jan 9, 2025
38bb709
Method for task1 updated and refactored
Jan 9, 2025
af8e232
Initial test for task 2 completed
Jan 9, 2025
a5eeeca
easiest possible method for task 2 completed, small adjustment to tes…
Jan 9, 2025
190f869
Method for task 2 adjusted
Jan 9, 2025
d9f099c
Initial test for task 3 completed
Jan 9, 2025
552690d
Initial method for task 3 completed
Jan 9, 2025
c68972b
completed method for task 3, also i forgot to commit the 2nd test for…
Jan 9, 2025
bbbdc4c
intial test for task 4 completed
Jan 9, 2025
205afc8
intial method for task 4 completed
Jan 9, 2025
cc63bd4
Initial test for task 5 completed
Jan 9, 2025
7971417
Initial method for task 5 completed
Jan 9, 2025
9f4bb14
Completed method for tasl 5, minor changes in test 5 and 4
Jan 9, 2025
002b326
inital test for task 6
Jan 9, 2025
b02b792
inital method for task 6
Jan 9, 2025
b3cb3c3
added another test for task 6
Jan 9, 2025
7c8befb
completed method for task 6
Jan 9, 2025
80964bd
initial test for task 7 completed
Jan 9, 2025
62ff0e5
initial method for task 7 completed
Jan 9, 2025
157cd0e
Changes made for test 7
Jan 9, 2025
3177249
Completed method for task 7, also discovered som errors that corrected.
Jan 9, 2025
33bf41b
Initial test for task 8 completed
Jan 9, 2025
a5e134e
Initial method for task 8 completed
Jan 9, 2025
a78388e
method for task 8 completed
Jan 9, 2025
1e1da61
test for task 9 completed
Jan 9, 2025
d15f232
Method for task 9 completed
Jan 9, 2025
1d190bc
fixed some typos.
Jan 9, 2025
73fa7eb
Updated code so that the HashMap is populated in the test-file instead.
Jan 14, 2025
ad5180a
Made new classes for the extension
Jan 15, 2025
9cc78f9
Initial test for getTaskByID() in TodoListExtension completed
Jan 15, 2025
c5ba5a7
Redid the test for getTaskByID() in TodoListExtension. Wanted a Strin…
Jan 15, 2025
2bdce19
Initial method getTaskByID() in TodoListExtension completed
Jan 15, 2025
7965664
method getTaskByID() in TodoListExtension completed
Jan 15, 2025
1174ce0
did another test for getTaskByID() in TodoListExtension
Jan 15, 2025
ff00fc2
initial test for updateNameByID() completed
Jan 15, 2025
23f9611
initial method for updateNameByID() completed
Jan 15, 2025
b93561d
method for updateNameByID() completed, also added another task for th…
Jan 15, 2025
6fd2b50
first test completed for extension 3, method updateStatusByID()
Jan 15, 2025
396d060
initial method completed for extension 3, method updateStatusByID()
Jan 15, 2025
5e878d8
added another test for extension 3, method updateStatusByID()
Jan 15, 2025
4ca1ce9
Method for extension 3 completed, method updateStatusByID()
Jan 15, 2025
feded28
Added private LocalDateTime to TodoItem class. I Also did the initial…
Jan 15, 2025
bdcb4ec
initial method for extension 4 completed
Jan 15, 2025
8216889
method for extension 4 completed
Jan 15, 2025
8655376
Method showDateTimeForEachTask() for Extension 4, completed. Changed …
Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## Todo

| Method | Member Variable | Scenario | Result |
|-----------------------------------------------|--------------------------------|-------------------------------------------------------------------------------|------------------------------------|
| add(String name) | HashMap<String, Boolean> tasks | Task with the provided name is not already in the todolist | true |
| | | Task with the provided name is already in the todolist | false |
| | | | |
| listTasks( ) | | There are tasks in the todolist | string with all tasks |
| | | There are no tasks in the todolist | string with error message |
| | | | |
| updateTaskStatus(String name, Boolean status) | | There is a task with the provided name and has the requested status | true |
| | | There is no task with the provided name or does not have the requested status | false |
| | | | |
| getCompletedTasks() | | There are completed tasks in the todolist | string with all completed tasks |
| | | There are no completed tasks in the todolist | string with error message |
| | | | |
| getUncompletedTasks() | | There are uncompleted tasks in the todolist | string with all uncompleted tasks |
| | | There are no uncompleted tasks in the todolist | string with error message |
| | | | |
| SearchTask(String) | | There was a task with the provided name | string with the task |
| | | There was no task with the provided name | string with error message |
| | | | |
| removeTask(String) | | Task with the provided name is not in the todolist | true |
| | | Task with the provided name is in the todolist | false |
| | | | |
| taskDescending() | | There are tasks in the todolist | string in descending order by name |
| | | There are no tasks in the todolist | string with error message |
| | | | |
| taskAscending() | | There are tasks in the todolist | string in ascending order by name |
| | | There are no tasks in the todolist | string with error message |



# Extension

## Todo

| Method | Member Variable | Scenario | Result |
|----------------------------------------------|-----------------------|----------|--------|
| add(String name) | ArrayList<Task> tasks | | |
| | id | | |
| listTasks( ) | | | |
| updateTaskStatus(Task task, Boolean state) | | | |
| | | | |
| getCompletedTasks() | | | |
| getNotCompletedTasks() | | | |
| SearchTask(Task task) | | | |
| removeTask(Task task) | | | |
| taskDescending() | | | |
| taskAscending() | | | |
| getTaskById(int id) | | | |
| updateTaskName(int id, String newName) | | | |
| updateTaskStatusById(int id, Boolean status) | | | |
| | | | |

## Task

| Method | Member Variable | Scenario | Result |
|--------|------------------|----------|--------|
| | | | |
| | Boolean complete | | |
| | String name | | |
138 changes: 138 additions & 0 deletions src/main/java/com/booleanuk/core/TodoList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,143 @@
package com.booleanuk.core;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

public class TodoList {

HashMap<String, Boolean> tasks;

public TodoList(HashMap<String, Boolean> tasks){
this.tasks = tasks;
}


// Task 1
public boolean add(String taskName){
if(!this.tasks.containsKey(taskName)){
this.tasks.put(taskName, false);
return true;
}
return false;
}


// Task 2
public String listTasks(){
if(this.tasks.isEmpty()){
return "The todolist does not contain any tasks!";
}
String listOfTasks = "";
for(String task : this.tasks.keySet()){
listOfTasks += task + ", ";
}
return listOfTasks;
}


// Task 3
public boolean updateTaskStatus(String task, Boolean status){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look right; we should be using accessors here

if(this.tasks.containsKey(task)){
this.tasks.put(task, status);
return true;
}
return false;
}


// Task 4
public String getCompletedTasks(){
String completedTasks = "";
for(String task : this.tasks.keySet()){
if(this.tasks.get(task).equals(true)){
completedTasks += task + ", ";
}
}
if(!completedTasks.equals("")){
return completedTasks;
}
return "There are no completed tasks!";
}


// Task 5
public String getUncompletedTasks(){
String uncompletedTasks = "";
for(String task : this.tasks.keySet()){
if(this.tasks.get(task).equals(false)){
uncompletedTasks += task + ", ";
}
}
if(!uncompletedTasks.equals("")){
return uncompletedTasks;
}
return "There are no uncompleted tasks!";
}


// Task 6
public String SearchTask(String task){
if(this.tasks.containsKey(task)){
return "The task exist!";
}
return "The task does not exist!";
}


// Task 7
public Boolean removeTask(String task){
if(this.tasks.containsKey(task)){
this.tasks.remove(task);
return true;
}
return false;
}


// Task 8
public String taskDescending(){
if(this.tasks.isEmpty()){
return "The todolist does not contain any tasks!";
}
else{
ArrayList<String> sortedKeys = new ArrayList<>(this.tasks.keySet());
Collections.sort(sortedKeys);
Collections.reverse(sortedKeys);
String tasksDescending = "";

for(String task : sortedKeys){
if(!task.equals(sortedKeys.getLast())){
tasksDescending += task + ", ";
}
else{
tasksDescending += task;
}
}
return tasksDescending;
}
}


// Task 9
public String taskAscending(){
if(this.tasks.isEmpty()){
return "The todolist does not contain any tasks!";
}
else{
ArrayList<String> sortedKeys = new ArrayList<>(this.tasks.keySet());
Collections.sort(sortedKeys);
String tasksAscending = "";

for(String task : sortedKeys){
if(!task.equals(sortedKeys.getLast())){
tasksAscending += task + ", ";
}
else{
tasksAscending += task;
}
}
return tasksAscending;
}
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/booleanuk/extension/TodoItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.booleanuk.extension;

import java.time.LocalDate;
import java.time.LocalDateTime;

public class TodoItem {
private String name;
private Boolean completed;
private final Integer todoID;
private LocalDateTime dateTime;

public TodoItem(Integer todoID, String name, Boolean completed, LocalDateTime dateTime){
this.todoID = todoID;
this.name = name;
this.completed = false;
this.dateTime = dateTime;
}

public LocalDateTime getDateTime() {
return dateTime;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Boolean getCompleted() {
return completed;
}

public void setCompleted(Boolean completed) {
this.completed = completed;
}

public Integer getTodoID() {
return todoID;
}
}
60 changes: 60 additions & 0 deletions src/main/java/com/booleanuk/extension/TodoListExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.booleanuk.extension;

import java.util.ArrayList;
import java.util.HashMap;

public class TodoListExtension {
private ArrayList<TodoItem> tasks;
private static long idCounter = 0;

public TodoListExtension(ArrayList<TodoItem> tasks){
this.tasks = tasks;
}

public String getTaskByID(Integer id){
for(TodoItem item : tasks){
if(item.getTodoID().equals(id)){
if(item.getCompleted()){
return item.getName() + ", completed";
} else {
return item.getName() + ", not completed";
}
}
}
return "ID is not in todo list";
}

public String updateNameByID(Integer id, String newName){
for(TodoItem item : tasks){
if(item.getTodoID().equals(id)){
item.setName(newName);
return "Task with ID " + id + " has a new name: " + newName;
}
}
return "ID is not in todo list";
}

public String updateStatusByID(Integer id, Boolean status){
for(TodoItem item : tasks){
if(item.getTodoID().equals(id)){
if(status){
return "Task with ID " + id + " has a new status: completed";
}else {
return "Task with ID " + id + " has a new status: incomplete";
}
}
}
return "ID is not in todo list";
}

public String showDateTimeForEachTask(){
String tasks = "";
if(!this.tasks.isEmpty()){
for(TodoItem item : this.tasks){
tasks += "Task with id: " + item.getTodoID() + ", " + item.getName() + ", was created: " + item.getDateTime().toString() + "\n";
}
return tasks;
}
return "There are no tasks in the list!";
}
}
Loading
Loading