|
|
@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
|
import java.time.LocalTime;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Semesteraufgabe {
|
|
|
|
|
|
|
|
public static ArrayList<String> words = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ArrayList<String> getLinesfromFile(String filename) throws FileNotFoundException {
|
|
|
|
|
|
|
|
Scanner input = new Scanner(new File(filename));
|
|
|
|
|
|
|
|
ArrayList<String> lines = new ArrayList<>();
|
|
|
|
|
|
|
|
while (input.hasNextLine()) {
|
|
|
|
|
|
|
|
lines.add(input.nextLine());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
input.close();
|
|
|
|
|
|
|
|
return lines;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ArrayList<String> getDosisFromFile() throws FileNotFoundException {
|
|
|
|
|
|
|
|
ArrayList<String> lines = getLinesfromFile("src/dosierung.txt");
|
|
|
|
|
|
|
|
for (String line : lines) {
|
|
|
|
|
|
|
|
String[] einzelwort = line.split(" ");
|
|
|
|
|
|
|
|
for (String wort : einzelwort) {
|
|
|
|
|
|
|
|
words.add(wort);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return words;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
|
|
|
Scanner input = new Scanner(System.in);
|
|
|
|
|
|
|
|
LocalTime morgens = LocalTime.of(12, 00);
|
|
|
|
|
|
|
|
LocalTime abends = LocalTime.of(18, 00);
|
|
|
|
|
|
|
|
getDosisFromFile();
|
|
|
|
|
|
|
|
System.out.println("Help -> Liste der Eingaben");
|
|
|
|
|
|
|
|
SimpleDateFormat newFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
|
|
|
|
|
|
|
double dose;
|
|
|
|
|
|
|
|
Date now;
|
|
|
|
|
|
|
|
double ie;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
String eingabe = input.nextLine();
|
|
|
|
|
|
|
|
if (eingabe.equalsIgnoreCase("help")) {
|
|
|
|
|
|
|
|
System.out.println(
|
|
|
|
|
|
|
|
"Dosierung -> Insulindosis überprüfen/ändern \nRechnen -> Insulindosis anhand der Kohlenhydrate berechnen + Eintrag machen \nEintrag -> Eintrag in das Tagebuch hinzufügen \nTagebuch -> Tagebuch lesen \nStop -> Programm beenden");
|
|
|
|
|
|
|
|
} else if (eingabe.equalsIgnoreCase("stop")) {
|
|
|
|
|
|
|
|
input.close();
|
|
|
|
|
|
|
|
System.out.println("Programm beendet");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else if (eingabe.equalsIgnoreCase("dosierung")) {
|
|
|
|
|
|
|
|
System.out.println("Prüfen oder ändern?");
|
|
|
|
|
|
|
|
String eingabe1 = input.nextLine();
|
|
|
|
|
|
|
|
if (eingabe1.equalsIgnoreCase("prüfen")) {
|
|
|
|
|
|
|
|
Scanner scanner = new Scanner(new File("src/dosierung.txt"));
|
|
|
|
|
|
|
|
while (scanner.hasNext()) {
|
|
|
|
|
|
|
|
System.out.println(scanner.nextLine());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (eingabe1.equalsIgnoreCase("ändern")) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
System.out.println("Eingabe in ganzen Zahlen!");
|
|
|
|
|
|
|
|
FileWriter dosierung = new FileWriter("src/dosierung.txt");
|
|
|
|
|
|
|
|
System.out.println("Dosis morgens in IE:");
|
|
|
|
|
|
|
|
String dos11 = input.nextLine();
|
|
|
|
|
|
|
|
int dos1 = Integer.parseInt(dos11);
|
|
|
|
|
|
|
|
dosierung.write("Morgens : " + dos1 + " IE pro KE");
|
|
|
|
|
|
|
|
dosierung.write(System.getProperty("line.separator"));
|
|
|
|
|
|
|
|
System.out.println("Dosis mittags in IE:");
|
|
|
|
|
|
|
|
String dos22 = input.nextLine();
|
|
|
|
|
|
|
|
int dos2 = Integer.parseInt(dos22);
|
|
|
|
|
|
|
|
dosierung.write("Mittags : " + dos2 + " IE pro KE");
|
|
|
|
|
|
|
|
dosierung.write(System.getProperty("line.separator"));
|
|
|
|
|
|
|
|
System.out.println("Dosis abends in IE:");
|
|
|
|
|
|
|
|
String dos33 = input.nextLine();
|
|
|
|
|
|
|
|
int dos3 = Integer.parseInt(dos33);
|
|
|
|
|
|
|
|
dosierung.write("Abends : " + dos3 + " IE pro KE");
|
|
|
|
|
|
|
|
System.out.println("Dosierung erfolgreich geändert");
|
|
|
|
|
|
|
|
dosierung.close();
|
|
|
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
|
|
|
System.out.println(
|
|
|
|
|
|
|
|
"Bitte eine Zahl eingeben! Bitte erstellen Sie eine neue Insulindosisliste über -> dosierung -> ändern");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
System.out.println("Falsche Eingabe!");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (eingabe.equalsIgnoreCase("rechnen")) {
|
|
|
|
|
|
|
|
System.out.println("Eintrag erstellen?");
|
|
|
|
|
|
|
|
String eingabe2 = input.nextLine();
|
|
|
|
|
|
|
|
if (eingabe2.equalsIgnoreCase("ja")) {
|
|
|
|
|
|
|
|
try (FileWriter writer1 = new FileWriter("src/Tagebuch", true)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
now = new Date();
|
|
|
|
|
|
|
|
System.out.println("Wie hoch ist ihr Blutzucker?");
|
|
|
|
|
|
|
|
String bz1 = input.nextLine();
|
|
|
|
|
|
|
|
int bz = Integer.parseInt(bz1);
|
|
|
|
|
|
|
|
System.out.println("Wie viele Kohlenhydrate in Gramm?");
|
|
|
|
|
|
|
|
String kh1 = input.nextLine();
|
|
|
|
|
|
|
|
double kh = Double.parseDouble(kh1);
|
|
|
|
|
|
|
|
LocalTime jetzt = LocalTime.now();
|
|
|
|
|
|
|
|
if (jetzt.isBefore(morgens)) {
|
|
|
|
|
|
|
|
dose = Double.parseDouble(words.get(2));
|
|
|
|
|
|
|
|
ie = (kh / 10 * dose);
|
|
|
|
|
|
|
|
System.out.println("So viel Insulin: " + ie);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jetzt.isBefore(abends)) {
|
|
|
|
|
|
|
|
dose = Double.parseDouble(words.get(8));
|
|
|
|
|
|
|
|
ie = (kh / 10 * dose);
|
|
|
|
|
|
|
|
System.out.println("So viel Insulin: " + ie);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
dose = Double.parseDouble(words.get(14));
|
|
|
|
|
|
|
|
ie = (kh / 10 * dose);
|
|
|
|
|
|
|
|
System.out.println("So viel Insulin: " + ie);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
writer1.write(newFormat.format(now) + ": Blutzucker: " + bz + " Kohlenhydrate: " + kh
|
|
|
|
|
|
|
|
+ " Dosis: " + dose + " Bolus: " + ie);
|
|
|
|
|
|
|
|
writer1.write("\n");
|
|
|
|
|
|
|
|
System.out.println("Eintrag erfolgreich hinzugefügt");
|
|
|
|
|
|
|
|
writer1.close();
|
|
|
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
|
|
|
System.out.println("Fehler! Nächstes Mal geben Sie bitte eine Zahl ein");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
System.out.println("Fehler beim Erstellen des Eintrags");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (eingabe2.equalsIgnoreCase("nein")) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
System.out.println("Wie viele Kohlenhydrate in Gramm?");
|
|
|
|
|
|
|
|
String kh1 = input.nextLine();
|
|
|
|
|
|
|
|
double kh = Double.parseDouble(kh1);
|
|
|
|
|
|
|
|
LocalTime jetzt = LocalTime.now();
|
|
|
|
|
|
|
|
if (jetzt.isBefore(morgens)) {
|
|
|
|
|
|
|
|
dose = Double.parseDouble(words.get(2));
|
|
|
|
|
|
|
|
System.out.println("So viel Insulin: " + (kh / 10 * dose));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jetzt.isBefore(abends)) {
|
|
|
|
|
|
|
|
dose = Double.parseDouble(words.get(8));
|
|
|
|
|
|
|
|
System.out.println("So viel Insulin: " + (kh / 10 * dose));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
dose = Double.parseDouble(words.get(14));
|
|
|
|
|
|
|
|
System.out.println("So viel Insulin: " + (kh / 10 * dose));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
|
|
|
System.out.println("Fehler! Nächstes Mal geben Sie bitte eine Zahl ein");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
System.out.println("Falsche Eingabe");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (eingabe.equalsIgnoreCase("tagebuch")) {
|
|
|
|
|
|
|
|
Scanner reader = new Scanner(new File("src/Tagebuch"));
|
|
|
|
|
|
|
|
while (reader.hasNext()) {
|
|
|
|
|
|
|
|
System.out.println(reader.nextLine());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (eingabe.equalsIgnoreCase("eintrag")) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
System.out.println(
|
|
|
|
|
|
|
|
"Damit der Eintrag sich den anderen gleicht -> Zuerst das Datum im Format : dd.MM.yyyy HH.mm :");
|
|
|
|
|
|
|
|
String datum = input.nextLine();
|
|
|
|
|
|
|
|
System.out.println(
|
|
|
|
|
|
|
|
"Jetzt die Kohlenhydrateinheiten, die Sie zur angegebenen Uhrzeit gegessen haben :");
|
|
|
|
|
|
|
|
String kh = input.nextLine();
|
|
|
|
|
|
|
|
int kh1 = Integer.parseInt(kh);
|
|
|
|
|
|
|
|
System.out.println(
|
|
|
|
|
|
|
|
"Und jetzt die Insulineinheiten, die Sie für das gegessene Essen gespritzt haben :");
|
|
|
|
|
|
|
|
String ie1 = input.nextLine();
|
|
|
|
|
|
|
|
Double ie11 = Double.parseDouble(ie1);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
FileWriter writer1 = new FileWriter("src/Tagebuch");
|
|
|
|
|
|
|
|
writer1.write(datum + " : Kohlenhydrate: " + kh1 + " Dosis: " + ie11);
|
|
|
|
|
|
|
|
writer1.write("\n");
|
|
|
|
|
|
|
|
writer1.close();
|
|
|
|
|
|
|
|
System.out.println("Eintrag erfolgreich hinzugefügt");
|
|
|
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
System.out.println("Fehler beim Erstellen des Eintrags");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
|
|
|
System.out.println("Fehler! Versuchen Sie nächstes Mal eine Zahl einzugeben");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
System.out.println("Unbekannte Eingabe");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|