-
Notifications
You must be signed in to change notification settings - Fork 129
Mattias Hedbom #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Hedbom98
wants to merge
47
commits into
boolean-uk:main
Choose a base branch
from
Hedbom98:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mattias Hedbom #126
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
e0bee06
First test
13a72c6
Easiest possible way to pass task1
e246d32
new test for task1 that will fail at the moment
38bb709
Method for task1 updated and refactored
af8e232
Initial test for task 2 completed
a5eeeca
easiest possible method for task 2 completed, small adjustment to tes…
190f869
Method for task 2 adjusted
d9f099c
Initial test for task 3 completed
552690d
Initial method for task 3 completed
c68972b
completed method for task 3, also i forgot to commit the 2nd test for…
bbbdc4c
intial test for task 4 completed
205afc8
intial method for task 4 completed
cc63bd4
Initial test for task 5 completed
7971417
Initial method for task 5 completed
9f4bb14
Completed method for tasl 5, minor changes in test 5 and 4
002b326
inital test for task 6
b02b792
inital method for task 6
b3cb3c3
added another test for task 6
7c8befb
completed method for task 6
80964bd
initial test for task 7 completed
62ff0e5
initial method for task 7 completed
157cd0e
Changes made for test 7
3177249
Completed method for task 7, also discovered som errors that corrected.
33bf41b
Initial test for task 8 completed
a5e134e
Initial method for task 8 completed
a78388e
method for task 8 completed
1e1da61
test for task 9 completed
d15f232
Method for task 9 completed
1d190bc
fixed some typos.
73fa7eb
Updated code so that the HashMap is populated in the test-file instead.
ad5180a
Made new classes for the extension
9cc78f9
Initial test for getTaskByID() in TodoListExtension completed
c5ba5a7
Redid the test for getTaskByID() in TodoListExtension. Wanted a Strin…
2bdce19
Initial method getTaskByID() in TodoListExtension completed
7965664
method getTaskByID() in TodoListExtension completed
1174ce0
did another test for getTaskByID() in TodoListExtension
ff00fc2
initial test for updateNameByID() completed
23f9611
initial method for updateNameByID() completed
b93561d
method for updateNameByID() completed, also added another task for th…
6fd2b50
first test completed for extension 3, method updateStatusByID()
396d060
initial method completed for extension 3, method updateStatusByID()
5e878d8
added another test for extension 3, method updateStatusByID()
4ca1ce9
Method for extension 3 completed, method updateStatusByID()
feded28
Added private LocalDateTime to TodoItem class. I Also did the initial…
bdcb4ec
initial method for extension 4 completed
8216889
method for extension 4 completed
8655376
Method showDateTimeForEachTask() for Extension 4, completed. Changed …
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | | | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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){ | ||
| 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; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
60
src/main/java/com/booleanuk/extension/TodoListExtension.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!"; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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