TODO List
parent
65ab8b6981
commit
1ba8e34a54
|
@ -0,0 +1,8 @@
|
|||
package TodoListApp.Domain.KlassenException;
|
||||
|
||||
public class FalscheEinagebException extends Exception {
|
||||
|
||||
public FalscheEinagebException(String error){
|
||||
super(error);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package TodoListApp.Domain.KlassenException;
|
||||
|
||||
public class TaskNichtGefundenException extends Exception {
|
||||
|
||||
public TaskNichtGefundenException(String error){
|
||||
super(error);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package TodoListApp.Domain;
|
||||
|
||||
public enum Prioritaet {
|
||||
Niedrig,Mittel,Hoch;
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package TodoListApp.Domain;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import TodoListApp.Domain.*;
|
||||
|
||||
public class Task {
|
||||
|
||||
private String title;
|
||||
private String beschreibung;
|
||||
private boolean istGemacht;
|
||||
private Prioritaet taskprioritaet;
|
||||
|
||||
public Task(String title, String beschreibung, Prioritaet taskprioritaet) {
|
||||
this.title = title;
|
||||
this.beschreibung = beschreibung;
|
||||
this.taskprioritaet = taskprioritaet;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getBeschreibung() {
|
||||
return beschreibung;
|
||||
}
|
||||
|
||||
public void setBeschreibung(String beschreibung) {
|
||||
this.beschreibung = beschreibung;
|
||||
}
|
||||
|
||||
public boolean isIstGemacht() {
|
||||
return istGemacht;
|
||||
}
|
||||
|
||||
public void setIstGemacht(boolean istGemacht) {
|
||||
this.istGemacht = istGemacht;
|
||||
}
|
||||
|
||||
public Prioritaet getTaskprioritaet() {
|
||||
return taskprioritaet;
|
||||
}
|
||||
|
||||
public void setTaskprioritaet(Prioritaet taskprioritaet) {
|
||||
this.taskprioritaet = taskprioritaet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "title=" + title + ", beschreibung=" + beschreibung + ((istGemacht == false) ? ", istGemacht = Nein" : ", istGemacht = Ja")
|
||||
+ ", taskprioritaet=" + taskprioritaet;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
package TodoListApp.Domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import TodoListApp.Domain.*;
|
||||
import TodoListApp.Domain.KlassenException.*;
|
||||
|
||||
public class TaskList {
|
||||
|
||||
private ArrayList<Task> alleTasks;
|
||||
private Task task;
|
||||
|
||||
|
||||
public TaskList() {
|
||||
|
||||
this.alleTasks = new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean addTask(String title, String beschreibung, String eingabeTaskprioritaet)throws FalscheEinagebException {
|
||||
Prioritaet taskPrioritaet = null;
|
||||
switch (eingabeTaskprioritaet) {
|
||||
case "niedrig":
|
||||
taskPrioritaet = taskPrioritaet.Niedrig;
|
||||
break;
|
||||
|
||||
case "mittel":
|
||||
taskPrioritaet = taskPrioritaet.Mittel;
|
||||
break;
|
||||
|
||||
case "hoch":
|
||||
taskPrioritaet = taskPrioritaet.Hoch;
|
||||
break;
|
||||
default:
|
||||
taskPrioritaet = taskPrioritaet.Niedrig;
|
||||
throw new FalscheEinagebException("Ungültige Priorität. Standardmäßig wird 'niedrig' verwendet");
|
||||
}
|
||||
task = new Task(title,beschreibung,taskPrioritaet);
|
||||
alleTasks.add(task);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public boolean removeTask(Task task) {
|
||||
|
||||
for (Task t : alleTasks) {
|
||||
if (t.getTitle().equalsIgnoreCase(task.getTitle())) {
|
||||
alleTasks.remove(task);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String findeTaskByTitle(String title) throws TaskNichtGefundenException {
|
||||
|
||||
for (Task t : alleTasks) {
|
||||
if (t.getTitle() == title)
|
||||
return t.toString();
|
||||
}
|
||||
throw new TaskNichtGefundenException("Task wurde nicht gefunden" );
|
||||
}
|
||||
|
||||
public ArrayList<String> getAlleGemachteTasks() {
|
||||
ArrayList<String> alleGemachteTasks = new ArrayList<>();
|
||||
for (Task t : alleTasks) {
|
||||
if (t.isIstGemacht() == true)
|
||||
alleGemachteTasks.add(t.toString());
|
||||
}
|
||||
return alleGemachteTasks;
|
||||
}
|
||||
|
||||
public ArrayList<String> printAllTask() {
|
||||
ArrayList<String> printallTasks = new ArrayList<>();
|
||||
int index = 1;
|
||||
for (Task t : alleTasks) {
|
||||
printallTasks.add(index++ + ".Task: " + t.toString() + ".");
|
||||
printallTasks.add("\n");
|
||||
}
|
||||
|
||||
|
||||
return printallTasks;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package TodoListApp;
|
||||
|
||||
import TodoListApp.Domain.KlassenException.FalscheEinagebException;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) throws FalscheEinagebException {
|
||||
new UserInterface();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package TodoListApp;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import TodoListApp.Domain.*;
|
||||
import TodoListApp.Domain.KlassenException.*;
|
||||
|
||||
public class UserInterface {
|
||||
private TaskList tasks;
|
||||
|
||||
UserInterface() throws FalscheEinagebException{
|
||||
tasks = new TaskList();
|
||||
startProgramm();
|
||||
}
|
||||
public void startProgramm() throws FalscheEinagebException {
|
||||
Scanner eingabe = new Scanner(System.in);
|
||||
String optionAuswahl;
|
||||
String title;
|
||||
String beschreibung;
|
||||
String taskprioritaet;
|
||||
boolean aktiv = true;
|
||||
System.out.println("<<Willkommen in meinem ToDo-List Programm>>");
|
||||
System.out.println();
|
||||
while (aktiv) {
|
||||
System.out.println();
|
||||
System.out.println("Wählen Sie Options bitte ein:");
|
||||
System.out.println("1. Task hinzufügen");
|
||||
System.out.println("2. Zeige Alle Tasks");
|
||||
System.out.println("5. Programm beenden");
|
||||
System.out.print(">");
|
||||
optionAuswahl = eingabe.nextLine().trim();
|
||||
switch (optionAuswahl) {
|
||||
case "1":
|
||||
System.out.println("Geben Sie Task ein: (title,beschreibung,taskprioritaet[niedrig,mittel,hoch]");
|
||||
System.out.print("Title:");
|
||||
System.out.print("> ");
|
||||
title = eingabe.nextLine().trim();
|
||||
|
||||
System.out.print("Beschreibung:");
|
||||
System.out.print("> ");
|
||||
beschreibung = eingabe.nextLine().trim();
|
||||
|
||||
System.out.print("Taskpriorität:");
|
||||
System.out.print("> ");
|
||||
taskprioritaet = eingabe.nextLine().trim();
|
||||
if (tasks.addTask(title, beschreibung, taskprioritaet))
|
||||
System.out.println("Task erfolgreich hinzugefügt");
|
||||
break;
|
||||
|
||||
case "2":
|
||||
for (String t : tasks.printAllTask())
|
||||
System.out.println(t);
|
||||
break;
|
||||
|
||||
case "5":
|
||||
aktiv = false;
|
||||
eingabe.close();
|
||||
System.out.println("Programm wird beendet!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue