hochladen

main
vincent 2025-01-13 16:07:39 +01:00
parent e525e8f42e
commit 9423f657c4
8 changed files with 280 additions and 0 deletions

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 23 [23]">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
TodoListe/.project 100644
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>TodoListe</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,77 @@
package Semesteraufgabe;
import java.util.Scanner;
public class Liste {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
TodoMap verwaltung = new TodoMap();
boolean running = true;
try {
System.out.println("Lege einen Namen für die Todo-Liste fest");
String dateiname = scanner.nextLine().replaceAll("[ ,.]", "_");
TodoDateiSchreiber todoDatei = new TodoDateiSchreiber(dateiname);
while (running) {
System.out.print("Was willst du tun? \nSchreibe 'help' für mehr informationen.\n");
String input = scanner.nextLine();
switch(input) {
case "neue Todo" :
System.out.println("Titel der Todo: \n");
String titel = scanner.nextLine();
System.out.println("Was muss erledigt werden? \n");
String beschreibung = scanner.nextLine();
verwaltung.addTodo(new Todos(titel, beschreibung));
break;
case "Todo anzeigen" :
System.out.print("Welche Nr.? \n");
System.out.println(verwaltung.openOneTodo(scanner.nextInt()));
break;
case "Alle Todos anzeigen" :
System.out.println(verwaltung.openAllTodos());
break;
case "Todo abhaken" :
System.out.println("Welche Nr.? \n");
int zahl = scanner.nextInt();
verwaltung.todoAbhacken(zahl);
break;
case "liste speichern" :
todoDatei.TodoSchreiben(verwaltung.openAllTodos());
break;
case "zurück" :
System.out.println("Programm wird beendet");
running = false;
break;
case "help" :
System.out.println("Befehle: \n"
+ " 'neue Todo': legt ein neues Todo an. \n"
+ " 'Todo anzeigen': Zeige eine bestimmte Todo \n"
+ " 'Alle Todos anzeigen: Zeige alle Todos \n"
+ " 'Todo abhaken: Setzt den Status der Todo auf 'erledigt' \n"
+ " 'liste speichern': speichert alle Todos in eine Textdatei \n"
+ " 'zurück': beendet das Programm \n");
break;
default: System.out.println("Falsche Eingabe. Versuche es nochmal. \n");
;
}
}
}
catch (Exception e) {
System.out.println("Ungültige Eingabe");
}
scanner.close();
}
}

View File

@ -0,0 +1,58 @@
package Semesteraufgabe;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TreeMap;
public class TodoDateiSchreiber {
private FileWriter writer;
private Date Datum = new Date();
private SimpleDateFormat DatumFormat = new SimpleDateFormat("dd-MM-yyyy HH-mm");
private String todoDatum = DatumFormat.format(Datum);
public TodoDateiSchreiber(String dateiname) {
try {
this.writer = new FileWriter("src/dateien/" + dateiname + ".txt");
System.out.println("Todoliste wird erstellt... \n");
}
catch (IOException e) {
System.out.println ("Fehler beim erstellen der Datei:");
}
}
public void TodoSchreiben (TreeMap<Integer, Todos> treeMap) {
try {
try {
System.out.println(todoDatum);
for (Todos todo : treeMap.values()) {
writer.write(todo.toString() + "\n");
System.out.println("todo wird bearbeitet");
}
}
catch (IOException e) {
System.out.println("Fehler beim Dateibearbeiten");
}
writer.close();
} catch (IOException ee) {
System.out.println("fehler beim speichern der datei");
}
finally {
try {
if (writer != null) {
writer.close();
System.out.println("Datei wurde geschlossen.");
}
} catch (IOException e) {
System.out.println("Fehler beim Schließen der Datei.");
e.printStackTrace();
}
}
}
}

View File

@ -0,0 +1,34 @@
package Semesteraufgabe;
import java.util.TreeMap;
public class TodoMap {
private TreeMap <Integer, Todos> liste;
public TodoMap () {
liste = new TreeMap<>();
}
public void addTodo (Todos todo) {
liste.put(todo.getTodoNr(), todo);
}
public TreeMap<Integer,Todos> openAllTodos () {
return liste;
}
public Todos openOneTodo (int nummer) {
return liste.get(nummer);
}
public void todoAbhacken(int nummer) {
if (liste.containsKey(nummer)) {
liste.get(nummer).setStatus(true);
} else {
System.out.println("To-Do mit dieser Nummer existiert nicht.");
}
}
}

View File

@ -0,0 +1,75 @@
package Semesteraufgabe;
public class Todos {
private String titel;
private String beschreibung;
private int todoNr;
private boolean status;
private static int counter = 1;
public Todos () {
titel = "To-do hat noch keinen Titel";
beschreibung = "To-do hat noch keine Beschreibung";
status = false;
todoNr++;
}
public Todos (String titel, String beschreibung) {
this.titel = titel;
this.beschreibung = beschreibung;
this.status = false;
this.todoNr = counter++;
}
public Todos (String titel, String beschreibung, String status) {
this.titel = titel;
this.beschreibung = beschreibung;
if ( status == "noch nicht erledigt" ) {
this.status = false;
}
else {
this.status = true;
}
}
public String toDoZustand(boolean status) {
if (this.status == false) {
return "noch nicht erledigt";
}
else {
return "Erledigt";
}
}
public String getTitel() {
return titel;
}
public void setTitel(String titel) {
this.titel = titel;
}
public String getBeschreibung() {
return beschreibung;
}
public void setBeschreibung(String beschreibung) {
this.beschreibung = beschreibung;
}
public int getTodoNr() {
return todoNr;
}
public void setTodoNr(int todoNr) {
this.todoNr = todoNr;
}
public boolean isStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
@Override
public String toString() {
return "Titel:" + titel + ", Beschreibung:" + beschreibung + ", To-Do Nr.: " + this.todoNr + ", Status: "
+ toDoZustand(status);
}
}

View File

@ -0,0 +1 @@
package Semesteraufgabe;

View File

@ -0,0 +1,8 @@
/**
*
*/
/**
*
*/
module TodoListe {
}