diff --git a/Programmierung2/src/TodoListApp/Domain/AddTask.java b/Programmierung2/src/TodoListApp/Domain/AddTask.java new file mode 100644 index 0000000..90d11d1 --- /dev/null +++ b/Programmierung2/src/TodoListApp/Domain/AddTask.java @@ -0,0 +1,29 @@ +package TodoListApp.Domain; + +public class AddTask { + + public static Task addTaskZuList(String title, String beschreibung, String eingabeTaskprioritaet) { + Task t; + 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; + } + + return t = new Task(title,beschreibung,taskPrioritaet); + + + } + +} diff --git a/Programmierung2/src/TodoListApp/Domain/KlassenException/FalscheEinagebException.java b/Programmierung2/src/TodoListApp/Domain/KlassenException/FalscheEinagebException.java deleted file mode 100644 index af4803f..0000000 --- a/Programmierung2/src/TodoListApp/Domain/KlassenException/FalscheEinagebException.java +++ /dev/null @@ -1,8 +0,0 @@ -package TodoListApp.Domain.KlassenException; - -public class FalscheEinagebException extends Exception { - - public FalscheEinagebException(String error){ - super(error); - } -} diff --git a/Programmierung2/src/TodoListApp/Domain/KlassenException/TaskNichtGefundenException.java b/Programmierung2/src/TodoListApp/Domain/KlassenException/TaskNichtGefundenException.java deleted file mode 100644 index 0990a7b..0000000 --- a/Programmierung2/src/TodoListApp/Domain/KlassenException/TaskNichtGefundenException.java +++ /dev/null @@ -1,8 +0,0 @@ -package TodoListApp.Domain.KlassenException; - -public class TaskNichtGefundenException extends Exception { - - public TaskNichtGefundenException(String error){ - super(error); - } -} diff --git a/Programmierung2/src/TodoListApp/Domain/TaskList.java b/Programmierung2/src/TodoListApp/Domain/TaskList.java index da68610..f54c8af 100644 --- a/Programmierung2/src/TodoListApp/Domain/TaskList.java +++ b/Programmierung2/src/TodoListApp/Domain/TaskList.java @@ -2,7 +2,6 @@ package TodoListApp.Domain; import java.util.ArrayList; import TodoListApp.Domain.*; -import TodoListApp.Domain.KlassenException.*; public class TaskList { @@ -14,46 +13,32 @@ public class TaskList { } public boolean addTaskZuList(String title, String beschreibung, String eingabeTaskprioritaet) { - 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; - } - - alleTasks.add(new Task(title, beschreibung, taskPrioritaet)); + Task t = AddTask.addTaskZuList(title, beschreibung, eingabeTaskprioritaet); + if (t == null) + return false; + + alleTasks.add(t); return true; } public boolean removeTask(String title) { - - for (Task t : alleTasks) { - if (t.getTitle().equalsIgnoreCase(title)) { - alleTasks.remove(t); - return true; - } - } - return false; + Task t = findTask(title); + if (t == null) + return false; + + alleTasks.remove(t); + return true; } - 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 boolean markTaskAsDone(String title) { + Task t = findTask(title); + if (t == null) + return false; + t.setIstGemacht(true); + return t.isIstGemacht(); } + + public ArrayList printAlleGemachteTasks() { ArrayList alleGemachteTasks = new ArrayList<>(); @@ -73,13 +58,11 @@ public class TaskList { return printallTasks; } - public boolean markTaskAsDone(String title) { - for (Task t : alleTasks) - if (t.getTitle().equalsIgnoreCase(title)) { - t.setIstGemacht(true); - return t.isIstGemacht(); - } - return false; + private Task findTask(String title) { + for (Task t : alleTasks) + if (t.getTitle().equalsIgnoreCase(title)) + return t; + return null; } } diff --git a/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java b/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java index d969c46..ccf2802 100644 --- a/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java +++ b/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java @@ -1,7 +1,6 @@ package TodoListApp.GUI_UserInterface; import TodoListApp.Domain.ProgrammSystem; -import TodoListApp.Domain.KlassenException.FalscheEinagebException; public class Userverwalter { @@ -20,24 +19,9 @@ public class Userverwalter { this.markTaskFenster = new MarkTask(); // Buttons User: - user.getAddTask().addActionListener(e -> { - try { - taskAddFenster(); - } catch (FalscheEinagebException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - }); - - - taskHinziFuegenFenster.getSubmitTask().addActionListener(e -> { - try { - addTask(); - } catch (FalscheEinagebException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - }); + user.getAddTask().addActionListener(e -> taskAddFenster()); + + taskHinziFuegenFenster.getSubmitTask().addActionListener(e ->addTask()); markTaskFenster.getMarkTaskButton().addActionListener(e -> markTaskAsDone()); taskLöschenFenster.getRemoveTaskButton().addActionListener(e-> removeTask()); @@ -49,12 +33,12 @@ public class Userverwalter { } - public void taskAddFenster() throws FalscheEinagebException { + public void taskAddFenster() { taskHinziFuegenFenster.zeigeFensterAddTask(); } - public void addTask() throws FalscheEinagebException { + public void addTask(){ String title = taskHinziFuegenFenster.getTasktitle().getText(); String beschreibung = taskHinziFuegenFenster.getTaskBeschreibung().getText(); diff --git a/Programmierung2/src/TodoListApp/Main.java b/Programmierung2/src/TodoListApp/Main.java index 5ab2c0a..ef1d93a 100644 --- a/Programmierung2/src/TodoListApp/Main.java +++ b/Programmierung2/src/TodoListApp/Main.java @@ -1,12 +1,10 @@ package TodoListApp; -import TodoListApp.Domain.KlassenException.FalscheEinagebException; -import TodoListApp.GUI_UserInterface.GUI_UserInterface; import TodoListApp.GUI_UserInterface.Userverwalter; public class Main { - public static void main(String[] args) throws FalscheEinagebException { + public static void main(String[] args) { new Userverwalter(); } diff --git a/Programmierung2/src/TodoListApp/UserInterface.java b/Programmierung2/src/TodoListApp/UserInterface.java index 356b894..d33996f 100644 --- a/Programmierung2/src/TodoListApp/UserInterface.java +++ b/Programmierung2/src/TodoListApp/UserInterface.java @@ -3,16 +3,15 @@ package TodoListApp; import java.util.Scanner; import TodoListApp.Domain.*; -import TodoListApp.Domain.KlassenException.*; public class UserInterface { private TaskList tasks; - UserInterface() throws FalscheEinagebException{ + UserInterface() { tasks = new TaskList(); - startProgramm(); + } - public void startProgramm() throws FalscheEinagebException { + public void startProgramm(){ Scanner eingabe = new Scanner(System.in); String optionAuswahl; String title;