Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2ef2755
Test adding to ArrayList() tasks fails
Aug 15, 2024
8f3d92b
Test adding to ArrayList() passes
Aug 15, 2024
15dfd98
Test if seeTasks() works fails
Aug 15, 2024
9d4da6e
Test if seeTasks() works fails, retry after corrections
Aug 15, 2024
360bf76
Test if seeTasks() works passes
Aug 15, 2024
5634dcd
Test if changeStatus() works fails
Aug 15, 2024
d10280a
Test if changeStatus() works passes
Aug 15, 2024
cd459b8
Retry of test if changeStatus() works fails
Aug 15, 2024
5a2c5b4
Retry of test if changeStatus() works fails
Aug 15, 2024
c451ef7
Retry of test if changeStatus() works passes
Aug 15, 2024
c74cb15
Test if seeCompletedTasks() works fails
Aug 15, 2024
07a8c32
Test if seeCompletedTasks() works passes
Aug 15, 2024
ad1994b
Test if seeIncompleteTasks() works fail
Aug 15, 2024
d3a81b9
Test if seeIncompleteTasks() works fails again
Aug 15, 2024
808fd10
Test if seeIncompleteTasks() works passes
Aug 15, 2024
c7d4800
Test if search() works fails
Aug 15, 2024
83ede24
Test if search() works passes
Aug 15, 2024
6c3d6bb
Test if search() works version 2 fails
Aug 15, 2024
f7aaa6c
Test if search() works version 2 passes
Aug 15, 2024
8d70ae1
Test if remove() works fails
Aug 15, 2024
9cd64c2
Test if remove() works passes
Aug 15, 2024
bea18c7
Test if seeTasksAscending() works fails
Aug 15, 2024
594b2d9
Test if seeTasksAscending() works passes
Aug 15, 2024
22676cc
Test if seeTasksDescending() works fails
Aug 15, 2024
f9de509
Test if seeTasksDescending() works passes
Aug 15, 2024
a48de94
Test if seeTasksDescending() works passes
Aug 15, 2024
c6e7c28
Test if getTaskById() works fails
Aug 15, 2024
2681856
Test if getTaskById() works passes
Aug 15, 2024
dda16a4
Test setNameById() fail
Aug 15, 2024
4856d04
Test setNameById() pass
Aug 15, 2024
8c5fd68
Test changeStatusById() fail
Aug 15, 2024
67da8fd
Test changeStatusById() pass
Aug 15, 2024
eb789be
Test seeDates() fail
Aug 15, 2024
9b9a830
Test seeDates() pass
Aug 15, 2024
8edde34
Retry to change name so that I can be seen on github
Aug 16, 2024
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
22 changes: 22 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
| Classes | Variables | Methods | Scenario | Outcomes |
|------------|-------------------------|------------------------------------------|------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| `TodoList` | `ArrayList<Task> tasks` | `add(Task task)` | I want to add tasks to my todo list. | task is added to tasks and return confirmation print |
| | | `seeTasks()` | I want to see all the tasks in my todo list. | Return print of elements in task |
| | | `changeStatus(Task task)` | Change status of task in tasks | Change completed and return completed |
| | | `seeTasksCompleted()` | I want to be able to get only the complete tasks. | Return print of completed elements in task |
| | | `seeTasksIncomplete()` | I want to be able to get only the incomplete tasks. | Return print of incomplete elements in task |
| | | `search(String task)` | Search for task in tasks | Return print of status |
| | | | Search for task not in tasks | Return not found print |
| | | `remove(Task task)` | Remove task in tasks | Return confirmation print |
| | | | Remove task not in tasks | Return not found print |
| | | `seeTasksAscending()` | I want to see all the tasks in my list ordered alphabetically in ascending order. | Return print of elements in task in alphabetically ascending order |
| | | `seeTasksDescending()` | I want to see all the tasks in my list ordered alphabetically in descending order. | Return print of elements in task in alphabetically descending order |
| | | `getTaskById(String id)` | I want to be able to get a task by a unique ID. | Return task |
| | | `setNameById(String id, String newName)` | I want to update the name of a task by providing its ID and a new name. | Return new name |
| | | `changeStatusById(String id)` | I want to be able to change the status of a task by providing its ID. | Return new status |
| | | `seeDates()` | I want to be able to see the date and time that I created each task. | Return print of dates and times |
| `Task` | `String name` | `getName()` | | Return name |
| | | `setName(String newName)` | | Set name to newName |
| | `String id` | `getId()` | | Return id |
| | `Boolean completed` | `getCompleted()` | | Return completed |
| | | `setCompleted(Boolean bool)` | | Set completed to bool |
16 changes: 16 additions & 0 deletions src/main/java/com/booleanuk/core/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.booleanuk.core;

public class Task {

private String name;
private Boolean completed;

Task(String name){
this.name = name;
this.completed = false;
}

public String getName(){return name;}
public Boolean getCompleted(){return completed;}
public void setCompleted(Boolean bool){completed = bool;}
}
123 changes: 123 additions & 0 deletions src/main/java/com/booleanuk/core/TodoList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,128 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class TodoList {

ArrayList<Task> tasks = new ArrayList<>();

public String add(Task task){
tasks.add(task);
String result = task.getName() + " added.";
return result;
}

public String seeTasks(){
String result = "";
for(Task task : tasks){
result += task.getName();

if(task.getCompleted()){
result += " completed";
}
else{
result += " incomplete";
}

if(tasks.getLast() != task){
result += ", ";
}
}
return result;
}

public Boolean changeStatus(Task task){
/*if(!tasks.contains(task)){
throw new Exception("Task not found!");
}*/
if(tasks.contains(task)){
if(task.getCompleted()){
task.setCompleted(false);
}
else{
task.setCompleted(true);
}
}
return task.getCompleted();
}

public String seeCompletedTasks(){
String result = "";
for(Task task : tasks){
if(task.getCompleted()){
result += task.getName();
if(tasks.getLast() != task){
result += ", ";
}
}
}
return result;
}

public String seeIncompleteTasks(){
String result = "";
for(Task task : tasks){
if(!task.getCompleted()){
result += task.getName();
if(tasks.getLast() != task){
result += ", ";
}
}
}
return result;
}

public String search(String searchedTask){
String result = "";
for(Task task : tasks){
if(task.getName().equals(searchedTask)){
result += task.getName();
if(task.getCompleted()){
result += " completed";
}
else{
result += " incomplete";
}
return result;
}
}
return "Task not found";
}

public String remove(Task task){
if(tasks.contains(task)){
tasks.remove(task);
return task.getName() + " removed";
}
return "Task not found";
}

public String seeTasksAscending(){
String result = "";
tasks.sort((t1, t2) -> t1.getName().compareTo(t2.getName()));
for(Task task : tasks){
result += task.getName();

if(tasks.getLast() != task){
result += " ";
}
}
return result;
}

public String seeTasksDescending(){
String result = "";
tasks.sort((t2, t1) -> t2.getName().compareTo(t1.getName()));
for(int i = tasks.size()-1; i > -1; --i){
result += tasks.get(i).getName();

if(tasks.getFirst() != tasks.get(i)){
result += " ";
}
}
return result;
}



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

import java.time.LocalDateTime;
import java.util.Date;
import java.util.UUID;

public class Task {

private String name;
private String id;
private Boolean completed;
private LocalDateTime date;

Task(String name){
this.name = name;
this.id = generateId();
this.completed = false;
this.date = LocalDateTime.now();
}

private String generateId(){
final String uuid = UUID.randomUUID().toString().replace("-", "");
return uuid;
}

public String getName(){return this.name;}
public void setName(String newName){this.name = newName;}
public Boolean getCompleted(){return this.completed;}
public void setCompleted(Boolean bool){this.completed = bool;}
public String getId(){return this.id;}
public LocalDateTime getDate(){return date;}

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

import java.time.temporal.ChronoUnit;
import java.util.ArrayList;

public class TodoList {

ArrayList<Task> tasks = new ArrayList<>();

public String add(Task task){
tasks.add(task);
String result = task.getName() + " added.";
return result;
}

public String seeTasks(){
String result = "";
for(Task task : tasks){
result += task.getName();

if(task.getCompleted()){
result += " completed";
}
else{
result += " incomplete";
}

if(tasks.getLast() != task){
result += ", ";
}
}
return result;
}

public Boolean changeStatus(Task task){
/*if(!tasks.contains(task)){
throw new Exception("Task not found!");
}*/
if(tasks.contains(task)){
if(task.getCompleted()){
task.setCompleted(false);
}
else{
task.setCompleted(true);
}
}
return task.getCompleted();
}

public String seeCompletedTasks(){
String result = "";
for(Task task : tasks){
if(task.getCompleted()){
result += task.getName();
if(tasks.getLast() != task){
result += ", ";
}
}
}
return result;
}

public String seeIncompleteTasks(){
String result = "";
for(Task task : tasks){
if(!task.getCompleted()){
result += task.getName();
if(tasks.getLast() != task){
result += ", ";
}
}
}
return result;
}

public String search(String searchedTask){
String result = "";
for(Task task : tasks){
if(task.getName().equals(searchedTask)){
result += task.getName();
if(task.getCompleted()){
result += " completed";
}
else{
result += " incomplete";
}
return result;
}
}
return "Task not found";
}

public String remove(Task task){
if(tasks.contains(task)){
tasks.remove(task);
return task.getName() + " removed";
}
return "Task not found";
}

public String seeTasksAscending(){
String result = "";
tasks.sort((t1, t2) -> t1.getName().compareTo(t2.getName()));
for(Task task : tasks){
result += task.getName();

if(tasks.getLast() != task){
result += " ";
}
}
return result;
}

public String seeTasksDescending(){
String result = "";
tasks.sort((t2, t1) -> t2.getName().compareTo(t1.getName()));
for(int i = tasks.size()-1; i > -1; --i){
result += tasks.get(i).getName();

if(tasks.getFirst() != tasks.get(i)){
result += " ";
}
}
return result;
}

public Task getTaskById(String id){
for(Task task : tasks){
if(task.getId().equals(id)){
return task;
}
}
return null;
}

public String setNameById(String id, String newName){
Task task = getTaskById(id);
task.setName(newName);
return task.getName();
}

public Boolean changeStatusById(String id){
return changeStatus(getTaskById(id));
//return null;
}

public String seeDates(){
String result = "";
for(Task task : tasks){
result += task.getName() + " " + task.getDate().truncatedTo(ChronoUnit.SECONDS).toString();

if(tasks.getLast() != task){
result += " ";
}
}
System.out.println(result);
return result;
}

}
Loading