-
Notifications
You must be signed in to change notification settings - Fork 129
Wilmer Winkler #125
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
base: main
Are you sure you want to change the base?
Wilmer Winkler #125
Changes from all commits
9f59904
8af3613
808747a
b7404aa
6f76d74
06bb7d1
c18d1ef
44d35f1
0a9ea13
7667e77
bebc4f1
2a3764d
2bc47e8
819af52
14ea150
1c3dae9
4c259c7
36d984e
d7536ce
62f3430
25ad0d5
f55454e
8f6a985
8470a0f
d867897
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | | | | |
| 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(){ | ||
| 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(){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous comment
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
| 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; | ||
| } | ||
|
|
||
| } |
| 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; | ||
| } | ||
|
|
||
|
|
||
| } |
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.
You could just iterate over the hashmap and use a stringbuilder to output the list of tasks, rather than creating a new list