add sort by time
This commit is contained in:
6
plan.txt
6
plan.txt
@@ -1,10 +1,12 @@
|
|||||||
Funktionen:
|
Funktionen:
|
||||||
|
-ToDo deadline#
|
||||||
|
-ToDo-Liste nach Datum/Uhrzeit sortieren#
|
||||||
|
-ToDo-Liste abspeichern
|
||||||
-ToDo hinzufügen#
|
-ToDo hinzufügen#
|
||||||
-ToDo abhaken#
|
-ToDo abhaken#
|
||||||
-ToDo deadline
|
|
||||||
-ToDo löschen#
|
-ToDo löschen#
|
||||||
-ToDo auflisten#
|
-ToDo auflisten#
|
||||||
-ToDo-Liste abspeichern
|
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-über Jarvis neue Einträge hinzufügen
|
-über Jarvis neue Einträge hinzufügen
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package de.dejan.todolist;
|
package de.dejan.todolist;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
@@ -22,7 +24,8 @@ public class Main{
|
|||||||
System.out.println("[2]ToDos auflisten");
|
System.out.println("[2]ToDos auflisten");
|
||||||
System.out.println("[3]ToDo abhaken/als nicht erledigt markieren");
|
System.out.println("[3]ToDo abhaken/als nicht erledigt markieren");
|
||||||
System.out.println("[4]ToDo löschen");
|
System.out.println("[4]ToDo löschen");
|
||||||
System.out.println("[5]Beenden");
|
System.out.println("[5]ToDos nach Deadline sortieren");
|
||||||
|
System.out.println("[6]Beenden");
|
||||||
System.out.print(">>>");
|
System.out.print(">>>");
|
||||||
|
|
||||||
int in=Integer.parseInt(System.console().readLine());
|
int in=Integer.parseInt(System.console().readLine());
|
||||||
@@ -32,7 +35,8 @@ public class Main{
|
|||||||
case 2: listToDo(); break;
|
case 2: listToDo(); break;
|
||||||
case 3: done(); break;
|
case 3: done(); break;
|
||||||
case 4: delTask(); break;
|
case 4: delTask(); break;
|
||||||
case 5: System.exit(0);
|
case 5: sortByDeadline(); break;
|
||||||
|
case 6: System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -42,7 +46,19 @@ public class Main{
|
|||||||
|
|
||||||
String in=System.console().readLine();
|
String in=System.console().readLine();
|
||||||
|
|
||||||
ToDo task=new ToDo(tasks.size(), in, false);
|
System.out.println("Datum und Zeit im Format [dd.MM.yyyy HH:mm] angeben!:");
|
||||||
|
String deadlineAsString=System.console().readLine();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ToDo task;
|
||||||
|
task = new ToDo(tasks.size(), in, false);
|
||||||
|
|
||||||
|
try {
|
||||||
|
task.setDeadline(new SimpleDateFormat("dd.MM.yyyy HH:mm").parse(deadlineAsString));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
tasks.add(task);
|
tasks.add(task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -50,7 +66,7 @@ public class Main{
|
|||||||
public static void listToDo(){
|
public static void listToDo(){
|
||||||
System.out.println("\n\nToDo:");
|
System.out.println("\n\nToDo:");
|
||||||
System.out.println("=====");
|
System.out.println("=====");
|
||||||
System.out.println("Nr. | ToDo | erledigt");
|
System.out.println("Nr. | ToDo | Deadline | erledigt");
|
||||||
for (int i = 0; i < tasks.size(); i++) {
|
for (int i = 0; i < tasks.size(); i++) {
|
||||||
char done_;
|
char done_;
|
||||||
if (tasks.get(i).getDone()) {
|
if (tasks.get(i).getDone()) {
|
||||||
@@ -58,7 +74,8 @@ public class Main{
|
|||||||
}else{
|
}else{
|
||||||
done_='N';
|
done_='N';
|
||||||
}
|
}
|
||||||
System.out.println("["+tasks.get(i).getID()+"] "+tasks.get(i).getContent()+" ["+done_+"]");
|
System.out.println("["+tasks.get(i).getID()+"] | ["+tasks.get(i).getContent()+"] | ["
|
||||||
|
+new SimpleDateFormat("dd.MM.yyyy HH:mm").format(tasks.get(i).getDeadline())+"] | ["+done_+"]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,4 +98,9 @@ public class Main{
|
|||||||
tasks.remove(Integer.parseInt(System.console().readLine()));
|
tasks.remove(Integer.parseInt(System.console().readLine()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void sortByDeadline(){
|
||||||
|
Collections.sort(tasks, new SortToDoByDate());
|
||||||
|
System.out.println("Sortiert...");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package de.dejan.todolist;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class SortToDoByDate implements Comparator<ToDo>{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(ToDo t1, ToDo t2) {
|
||||||
|
// https://stackoverflow.com/questions/5927109/sort-objects-in-arraylist-by-date
|
||||||
|
return t1.getDeadline().compareTo(t2.getDeadline());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +1,24 @@
|
|||||||
package de.dejan.todolist;
|
package de.dejan.todolist;
|
||||||
|
|
||||||
public class ToDo {
|
import java.util.*;
|
||||||
|
|
||||||
|
public class ToDo{
|
||||||
|
|
||||||
private int theID;
|
private int theID;
|
||||||
private String theContent;
|
private String theContent;
|
||||||
private boolean theDone;
|
private boolean theDone;
|
||||||
String theDeadline;
|
|
||||||
|
// https://docs.oracle.com/javase/8/docs/api/java/util/Date.html
|
||||||
|
// https://stackoverflow.com/questions/5927109/sort-objects-in-arraylist-by-date
|
||||||
|
private Date theDeadline;
|
||||||
|
|
||||||
|
|
||||||
|
public ToDo(int id, String content, boolean done, Date deadline){
|
||||||
|
theID=id;
|
||||||
|
theContent=content;
|
||||||
|
theDone=done;
|
||||||
|
theDeadline=deadline;
|
||||||
|
}
|
||||||
|
|
||||||
public ToDo(int id, String content, boolean done){
|
public ToDo(int id, String content, boolean done){
|
||||||
theID=id;
|
theID=id;
|
||||||
@@ -13,7 +26,6 @@ public class ToDo {
|
|||||||
theDone=done;
|
theDone=done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//get-& set-methods
|
//get-& set-methods
|
||||||
public void setID(int id){
|
public void setID(int id){
|
||||||
theID=id;
|
theID=id;
|
||||||
@@ -39,5 +51,12 @@ public class ToDo {
|
|||||||
return theDone;
|
return theDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDeadline(Date d){
|
||||||
|
theDeadline=d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDeadline(){
|
||||||
|
return theDeadline;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user