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
35 changes: 35 additions & 0 deletions src/main/java/com/booleanuk/core/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.booleanuk.core;

public class Task {
Boolean isComplete;
String description;

public Task(String description) {
this.description = description;
this.isComplete = false;
}

public Boolean isComplete() {
return this.isComplete;
}

void setComplete() {
this.isComplete = true;
}

void setIncomplete() {
this.isComplete = false;
}

@Override
public String toString() {
String str = "";
str += "Task " + description;
if (isComplete) {
str += ": Complete.";
return str;
}
str += ": Incomplete.";
return str;
}
}
110 changes: 110 additions & 0 deletions src/main/java/com/booleanuk/core/TodoList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,115 @@
package com.booleanuk.core;

import java.util.ArrayList;
import java.util.List;

public class TodoList {
List<Task> allTasks;

public TodoList() {
allTasks = new ArrayList<>();
}

public void addTask(Task t) {
if (!(allTasks.contains(t))) {
allTasks.add(t);
}
}

public void seeTasks() {
if (allTasks.isEmpty()) {
return;
}
for (Task t : allTasks) {
t.toString();
}
}

public List<Task> getCompleteTasks() {
List<Task> completed = new ArrayList<>();
for (Task t : allTasks) {
if (t.isComplete()) {
completed.add(t);
}
}
return completed;
}

public List<Task> getIncompleteTasks() {
List<Task> incomplete = new ArrayList<>();

for (Task t : allTasks) {
if (!t.isComplete()) {
incomplete.add(t);
}
}
return incomplete;
}

public Task searchForTask(String description) {
for (Task t : allTasks) {

if (t.description.equals(description)) {
return t;
}
}
noSuchTask();
return null;
}

public Task removeTask(Task t) {
allTasks.remove(t);
return t;
}

public List<Task> ascendingView() {
Task[] toBeSorted = new Task[allTasks.size()];
Task temp;

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

for (int i = 0; i < allTasks.size(); i ++) {
for (int j = i + 1; j < allTasks.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 ascending;
}

public List<Task> descendingView() {
Task[] toBeSorted = new Task[allTasks.size()];
Task temp;

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

for (int i = 0; i < allTasks.size(); i ++) {
for (int j = i + 1; j < allTasks.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 descending;
}

public Task noSuchTask() {
System.out.println("There is no such task in the todo-list.");
return null;
}
}
53 changes: 53 additions & 0 deletions src/main/java/com/booleanuk/extension/TaskExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.booleanuk.extension;

import java.time.LocalDateTime;

public class TaskExtension {
private Boolean isComplete;
private String description;
private final int id;
private LocalDateTime timeCreated;

public TaskExtension(int id, String description) {
this.id = id;
this.isComplete = false;
this.description = description;
timeCreated = LocalDateTime.now();
}

public int getId() {
return this.id;
}

public String getDescription() {
return this.description;
}

public LocalDateTime getTimeCreated() {
return this.timeCreated;
}

public Boolean isComplete() {
return this.isComplete;
}

public void setComplete() {
this.isComplete = true;
}

public void setIncomplete() {
this.isComplete = false;
}

@Override
public String toString() {
String str = "";
str += "Task " + description;
if (isComplete) {
str += ": Complete.";
return str;
}
str += ": Incomplete.";
return str;
}
}
155 changes: 155 additions & 0 deletions src/main/java/com/booleanuk/extension/TodoListExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package com.booleanuk.extension;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

public class TodoListExtension {
List<TaskExtension> allTasks;

public TodoListExtension() {
allTasks = new ArrayList<>();
}

public void addTask(TaskExtension t) {
if (!(allTasks.contains(t))) {
allTasks.add(t);
}
}

public void setTaskCompleteById(int otherId) {
for (TaskExtension t : allTasks) {
if (t.getId() == otherId) {
t.setComplete();
}
}
}

public void setTaskIncompleteById(int otherId) {
for (TaskExtension t : allTasks) {
if (t.getId() == otherId) {
t.setIncomplete();
}
}
}

public TaskExtension getTaskById(int id) {

for (TaskExtension t : allTasks) {
if (t.getId() == id) {
return t;
}
}
return null;
}

public void getTasks() {
// tests by comparing two TodoLists, is that ok?
if (allTasks.isEmpty()) {
return;
}

for (TaskExtension t : allTasks) {
t.toString();
}
}

public LocalDateTime getTaskTimeCreated(int id) {
if (allTasks.isEmpty()) {
return null;
}
return getTaskById(id).getTimeCreated();
}

public List<TaskExtension> getCompleteTasks() {

List<TaskExtension> completed = new ArrayList<>();
for (TaskExtension t : allTasks) {
if (t.isComplete()) {
completed.add(t);
}
}
return completed;
}

public List<TaskExtension> getIncompleteTasks() {

List<TaskExtension> incomplete = new ArrayList<>();

for (TaskExtension t : allTasks) {
if (!t.isComplete()) {
incomplete.add(t);
}
}
return incomplete;
}

public TaskExtension searchForTask(String description) {

for (TaskExtension t : allTasks) {

if (t.getDescription().equals(description)) {
return t;
}
}

noSuchTask();
return null;
}

public TaskExtension removeTask(TaskExtension t) {
allTasks.remove(t);
return t;
}

public List<TaskExtension> ascendingView() {
TaskExtension[] toBeSorted = new TaskExtension[allTasks.size()];
TaskExtension temp;

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

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

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

public List<TaskExtension> descendingView() {
TaskExtension[] toBeSorted = new TaskExtension[allTasks.size()];
TaskExtension temp;

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

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

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

public TaskExtension noSuchTask() {
System.out.println("There is no such task in the todo-list.");
return null;
}
}
Loading
Loading