Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 src/main/domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Requirements
as a user i want
I want to add tasks to my todo list.
I want to see all the tasks in my todo list.
I want to change the status of a task between incomplete and complete.
I want to be able to get only the complete tasks.
I want to be able to get only the incomplete tasks.
I want to search for a task and receive a message that says it wasn't found if it doesn't exist.
I want to remove tasks from my list.
I want to see all the tasks in my list ordered alphabetically in ascending order.
I want to see all the tasks in my list ordered alphabetically in descending order.



I want to add tasks to my todo list.


| Classes | Members | Methods | Scenario | Outputs |
|----------------------------------------------------|-------------------|---------------|----------------------------------|---------|
| `TodoList(List of Task objects (Also A object??))` | (`Task (Object)`) | `Add(Task())` | Add a task to todolist (success) | true |

I want to see all the tasks in my todo list.



| Classes | Members | Methods | Scenario | Outputs |
|----------------------------------|-------------------|-----------|--------------------------|---------------------------------|
| `TodoList(List of Task objects)` | (`Task (Object)`) | `show()` | if todolist is empty | false |
| | | | if todolist is has tasks | return tasks in todolist (true) |

I want to change the status of a task between incomplete and complete.
I want to be able to get only the complete tasks.
I want to be able to get only the incomplete tasks.
I want to search for a task and receive a message that says it wasn't found if it doesn't exist.
I want to remove tasks from my list.
I want to see all the tasks in my list ordered alphabetically in ascending order.


| Classes | Members | Methods | Scenario | Outputs |
|----------------------------------------------------|-------------------|-------------------------|-----------------------------------------------|--------------------------------|
| `TodoList(List of Task objects)` | (`Task (Object)`) | `changeStatus(Task() )` | if todolist has a task which is not completed | "Task turned to completed" |
| | | | if todolist has a task which is completed | "Task turned to not completed" |
| | | | if task is null | "task not found" |
| | | | | |
| `TodoList(List of Task objects)` | (`Task (Object)`) | `show()` | if todolist is empty | false |
| | | | if todolist is has tasks | return tasks in todolist |
| `TodoList(List of Task objects (Also A object??))` | (`Task (Object)`) | `Add(Task())` | Add a task to todolist (success) | true |
| | | | if task not exist | false |
| | | `completed()` | if zero completed tasks | false |
| | | | if there are completed tasks | true |
| | | `notCompleted()` | if all tasks completed or zero tasks | false |
| | | | if there are incompleted tasks | todolist with the tasks |
| | | `search(Task())` | if task is found | true |
| | | `remove(Task())` | if task is not found | false |
| | | | if task is found | returns the deleted task |
| | | `ascending()` | if todo list is empty | false |
| | | | if todo list has tasks | true |
| | | `descending()` | if todo list is empty | false |
| | | | if todo list has tasks | true |
| | | | | |


38 changes: 38 additions & 0 deletions src/main/java/com/booleanuk/core/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.booleanuk.core;

public class Task {
public String title;
public String description;
public boolean status;
//Assertions.assertEquals(newtask, todo.search("Do Homework"));
// Assertions.assertEquals(newtask2, todo.search("Make Food"));


public Task(String title, String description, boolean status) {
this.title = title;
this.description = description;
this.status = status;
}

public Task() {
this.title = "TheTitle";
this.description = "The Description";
this.status = false;
}

public String show(){
return "Here is the tasks\n"+ title +" " +description + " is it done? " + ((status) ? " JA " : " nei ");
}

public boolean isStatus() {
return status;
}

public void setStatus(boolean status) {
this.status = status;
}

public String getTitle() {
return title;
}
}
132 changes: 131 additions & 1 deletion src/main/java/com/booleanuk/core/TodoList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,135 @@
package com.booleanuk.core;

public class TodoList {
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public class TodoList { //should I use public variables or private?
public ArrayList<Task> tasks;


public TodoList(Task tasks) {
this.tasks = new ArrayList<Task>();
this.tasks.add(tasks);

}

public boolean addtask(Task addedtask){
this.tasks.add(addedtask);
// this.tasks.set(0, new Task());
return true;

}
public boolean show(){
for (Task task: tasks){
task.show();

}
return true;
}



public String changeStatus(Task addedtask){
if (addedtask.isStatus()){
addedtask.setStatus(false);
return "Task turned to not completed";
}
addedtask.setStatus(true);
return "Task turned to completed";
}

public boolean completed(){
boolean found = false;
for (Task task: tasks){
if (task.isStatus()){
task.show();
found = true;
}

}
return found;
}
public boolean notCompleted(){
boolean found = false;
for (Task task: tasks){
if (!task.isStatus()){
task.show();
found = true;
}

}
return found;
}
public boolean search(String query){
for (Task task: tasks){
if (Objects.equals(task.getTitle(), query)){
task.show();
return true;
}
}
return false;
}
public boolean remove(String title){

for (Task task: tasks){
if (Objects.equals(task.getTitle(), title)){
task.show();
tasks.remove((task));
return true;
}
}
return false;
}
public boolean ascending(){
Task[] toBeSorted = new Task[tasks.size()];
Task temp;

for (int i = 0; i < toBeSorted.length; i ++) {
toBeSorted[i] = tasks.get(i);
}

for (int i = 0; i < tasks.size(); i ++) {
for (int j = i + 1; j < tasks.size(); j ++) {

if (toBeSorted[i].description.compareTo(toBeSorted[j].description) > 0) {
temp = toBeSorted[i];
toBeSorted[i] = toBeSorted[j];
toBeSorted[j] = temp;
}
}
}
List<Task> ascending = new ArrayList<>();
ascending.addAll(List.of(toBeSorted));
return true;

}
public boolean descending(){
if (tasks.isEmpty()){
return false;
}

Task[] toBeSorted = new Task[tasks.size()];
Task temp;

for (int i = 0; i < toBeSorted.length; i ++) {
toBeSorted[i] = tasks.get(i);
}

for (int i = 0; i < tasks.size(); i ++) {
for (int j = i + 1; j < tasks.size(); j ++) {

if (toBeSorted[i].description.compareTo(toBeSorted[j].description) < 0) {
temp = toBeSorted[i];
toBeSorted[i] = toBeSorted[j];
toBeSorted[j] = temp;
}
}
}
List<Task> descending = new ArrayList<>();
descending.addAll(List.of(toBeSorted));
return true;
}

}
Loading
Loading