Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9f59904
Core domain model complete. Ignore the extension model
Jan 9, 2025
8af3613
Tests for add() function complete
Jan 9, 2025
808747a
Code for add() function complete and passed the tests.
Jan 9, 2025
b7404aa
Tests for listTasks() function complete.
Jan 9, 2025
6f76d74
Tests for listTasks() function remade and listTasks() function was ma…
Jan 9, 2025
06bb7d1
Tests for updateTaskStatus() function complete.
Jan 9, 2025
c18d1ef
updateTaskStatus() function complete and 1 change in the domain model
Jan 9, 2025
44d35f1
Tests for the updateTaskStatus() function complete and small change i…
Jan 9, 2025
0a9ea13
getCompletedTasks() function code completed with small fixes in test …
Jan 9, 2025
7667e77
getUncompletedTasks test hopefully done.
Jan 9, 2025
bebc4f1
getUncompletedTasks code complete.
Jan 9, 2025
2a3764d
searchTask() tests complete
Jan 9, 2025
2bc47e8
searchTask() function code complete and some fixes in the test.
Jan 9, 2025
819af52
removeTask() tests complete
Jan 9, 2025
14ea150
removeTask() function code complete
Jan 9, 2025
1c3dae9
taskDescending() tests complete
Jan 9, 2025
4c259c7
taskDescending() code complete
Jan 9, 2025
36d984e
tasksAscending() tests complete
Jan 9, 2025
d7536ce
Core done!
Jan 9, 2025
62f3430
Wilmer Winkler
Jan 9, 2025
25ad0d5
Small corrections to the domain model
Jan 9, 2025
f55454e
Small corrections to the domain model
Jan 9, 2025
8f6a985
Domain model updated and extensionTests are done.
Jan 13, 2025
8470a0f
Extension done!
Jan 13, 2025
d867897
Extension done!
Jan 15, 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 | List<string> with all tasks |
| | | There are no tasks in the todolist | List<string> with error message |
| | | | |
| updateTaskStatus(String name, Boolean status) | | There is a task with the provided name | true |
| | | There is no task with the provided name | false |
| | | | |
| getCompletedTasks() | | There are completed tasks in the todolist | List<string> with all completed tasks |
| | | There are no completed tasks in the todolist | List<string> with error message |
| | | | |
| getNotCompletedTasks() | | There are uncompleted tasks in the todolist | List<string> with all uncompleted tasks |
| | | There are no uncompleted tasks in the todolist | List<string> with error message |
| | | | |
| SearchTask(String) | | There was a task with the provided name | string with a message |
| | | 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 | List<string> in descending order by name |
| | | There are no tasks in the todolist | List<string> with error message |
| | | | |
| taskAscending() | | There are tasks in the todolist | List<string> in ascending order by name |
| | | There are no tasks in the todolist | List<string> with error message |



# Extension

## Todo

| Method | Member Variable | Scenario | Result |
|----------------------------------------------|-----------------------|---------------------------------------------------|--------|
| | ArrayList<Task> tasks | | |
| | | | |
| | | | |
| | | | |
| getTaskById(int id) | | Search after a task with an existing ID | String |
| | | Search after a task with no existing ID | String |
| | | | |
| updateTaskName(int id, String newName) | | Update a task that exists with a new name | true |
| | | Update a task that does not exist with a new name | false |
| | | | |
| updateTaskStatusById(int id, Boolean status) | | Update a task that exists to wished status | true |
| | | Update a task that exists to wished status | false |

## Task

| Method | Member Variable | Scenario | Result |
|---------------------|----------------------|----------|--------|
| | Static int idCounter | | |
| | int id | | |
| | String name | | |
| | Boolean complete | | |
| | String details | | |
| Getters and setters | | | |
128 changes: 128 additions & 0 deletions src/main/java/com/booleanuk/core/TodoList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,133 @@
package com.booleanuk.core;

import java.util.*;

public class TodoList {

public HashMap<String, Boolean> tasks = new HashMap<>();

public boolean add(String taskName){
if(tasks.containsKey(taskName)){
return false;
}
tasks.put(taskName, false);
return true;
}

public List<String> listTasks(){

Choose a reason for hiding this comment

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

You could just iterate over the hashmap and use a stringbuilder to output the list of tasks, rather than creating a new list

List<String> strings = new ArrayList<String>() {};
String errorMsg = "Your todolist is empty";


strings.addAll(tasks.keySet());


if(strings.isEmpty()) {
strings.add(errorMsg);
return strings;
}

return strings;
}

public boolean updateTaskStatus(String taskName, Boolean taskCompletion){
if(tasks.containsKey(taskName)){
tasks.replace(taskName, taskCompletion);
return true;
}
return false;
}

public List<String> getCompletedTasks(){

Choose a reason for hiding this comment

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

This does not seem quite right, but I think that is mostly due to the fact that you don't have a 'Task' class on which to set the 'status' property

List<String> strings = new ArrayList<String>() {};
String errorMsg = "You have no completed tasks";


for (String task : tasks.keySet()){
if(tasks.get(task)){
strings.add(task);

}
}

if(strings.isEmpty()) {
strings.add(errorMsg);
return strings;
}

return strings;
}

public List<String> getUnCompletedTasks(){

Choose a reason for hiding this comment

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

See previous comment

Copy link
Author

Choose a reason for hiding this comment

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

Is this something I need to fix to get a passing grade or something for me to have in mind in the future?

List<String> strings = new ArrayList<String>() {};
String errorMsg = "You have no uncompleted tasks";


for (String task : tasks.keySet()){
if(!tasks.get(task)){
strings.add(task);

}
}

if(strings.isEmpty()) {
strings.add(errorMsg);
return strings;
}

return strings;
}

public List<String> searchTask(String taskName){
List<String> strings = new ArrayList<String>() {};
String message = "There was no task with that name";


if(tasks.containsKey(taskName)){
message = "There is a task with that name";
strings.add(message);
return strings;
}
strings.add(message);

return strings;
}

public boolean removeTask(String taskName){
if(tasks.containsKey(taskName)){
tasks.remove(taskName);
return true;
}
return false;
}

public List<String> tasksDescending(){
List<String> strings = new ArrayList<String>(tasks.keySet()) {};
String errorMsg = "No tasks available";

Collections.sort(strings);

if(strings.isEmpty()){
strings.add(errorMsg);
return strings;
}

return strings;
}

public List<String> tasksAscending(){
List<String> strings = new ArrayList<String>(tasks.keySet()) {};
String errorMsg = "No tasks available";

Collections.sort(strings);

Collections.reverse(strings);

if(strings.isEmpty()){
strings.add(errorMsg);
return strings;
}

return strings;
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/booleanuk/extension/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.booleanuk.extension;

public class Task {

public static int idCounter = 0;
private int id;
private String name;
private Boolean complete;
private String details;

public Task(String name, String details){
id = idCounter++;
this.name = name;
this.details = details;
complete = false;
}

public Boolean getComplete() {
return complete;
}

public void setComplete(Boolean complete) {
this.complete = complete;
}

public String getDetails() {
return details;
}

public String getName() {
return name;
}

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

public int getId() {
return id;
}

}
58 changes: 58 additions & 0 deletions src/main/java/com/booleanuk/extension/TodoListExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.booleanuk.extension;

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

public class TodoListExtension {

public ArrayList<Task> extensionTask = new ArrayList<>();

public String getTaskByID(int id){
String output = "No task with that ID was found";
for(Task task : extensionTask){
if(id == task.getId()){
output = "ID: " + task.getId() + ", Name: " + task.getName() + ", Complete: " + task.getComplete() + ", Details: " + task.getDetails();
}
}

return output;
}

public Boolean updateTaskName(int id, String newName){
for(Task task : extensionTask){
if(id == task.getId()){
task.setName(newName);
}
}

for(Task task : extensionTask){
if(task.getName() == newName){
task.setName(newName);
return true;
}
}

return false;
}

public Boolean updateTaskStatusById(int id, Boolean status){
for(Task task : extensionTask){
if(id == task.getId()){
task.setComplete(status);
}
}

for(Task task : extensionTask){
if(id == task.getId()){
if(task.getComplete() == status){
return true;
}
}
}
return false;
}


}
Loading
Loading