From 177b73559edf3ec1a1938da145442bef25328a3b Mon Sep 17 00:00:00 2001 From: ifembanefo Date: Tue, 11 Apr 2023 11:16:05 +0200 Subject: [PATCH] =?UTF-8?q?akuteller=20Stand=20=C3=9Cbung,=20Teil=202=20fa?= =?UTF-8?q?st=20fertg=20und=20Teil=203=20angefangen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2Semester/myconf.cfg | 2 +- 2Semester/myconf.txt | 1 - 2Semester/myconf2.cfg | 1 - 2Semester/myconf2.txt | 0 2Semester/myconf3.txt | 0 2Semester/myconf4.txt | 1 - 2Semester/myconf5.txt | 1 - 2Semester/myconf6.txt | 3 - .../src/fakturierungssystem/Datenmodell.java | 53 +++++++-- .../fakturierungssystem/Persistierung.java | 41 ++++--- 2Semester/src/fakturierungssystem/UI.java | 53 ++++++--- 2Semester/src/indexverwaltung/Datei.java | 105 +++++++++++++----- 2Semester/src/indexverwaltung/IndexUI.java | 31 +++++- 13 files changed, 214 insertions(+), 78 deletions(-) delete mode 100644 2Semester/myconf.txt delete mode 100644 2Semester/myconf2.cfg delete mode 100644 2Semester/myconf2.txt delete mode 100644 2Semester/myconf3.txt delete mode 100644 2Semester/myconf4.txt delete mode 100644 2Semester/myconf5.txt delete mode 100644 2Semester/myconf6.txt diff --git a/2Semester/myconf.cfg b/2Semester/myconf.cfg index a89a386..2053804 100644 --- a/2Semester/myconf.cfg +++ b/2Semester/myconf.cfg @@ -1 +1 @@ -Firmenname "Apple"Firmenadresse "US"Bankverbindung "DE12345" \ No newline at end of file +Firmenadresse = "nijokp" diff --git a/2Semester/myconf.txt b/2Semester/myconf.txt deleted file mode 100644 index e0a266c..0000000 --- a/2Semester/myconf.txt +++ /dev/null @@ -1 +0,0 @@ -Firmenname "Google"Firmenadresse "US"Bankverbindung "US12456" \ No newline at end of file diff --git a/2Semester/myconf2.cfg b/2Semester/myconf2.cfg deleted file mode 100644 index d9e5b7b..0000000 --- a/2Semester/myconf2.cfg +++ /dev/null @@ -1 +0,0 @@ -Firmenname "Google"Firmenadresse "US"Bankverbindung "US12345" \ No newline at end of file diff --git a/2Semester/myconf2.txt b/2Semester/myconf2.txt deleted file mode 100644 index e69de29..0000000 diff --git a/2Semester/myconf3.txt b/2Semester/myconf3.txt deleted file mode 100644 index e69de29..0000000 diff --git a/2Semester/myconf4.txt b/2Semester/myconf4.txt deleted file mode 100644 index 55355b0..0000000 --- a/2Semester/myconf4.txt +++ /dev/null @@ -1 +0,0 @@ -Firmenname = "HelloFresh"Firmenadresse = "Mannheim"Bankverbindung ="DE567788" \ No newline at end of file diff --git a/2Semester/myconf5.txt b/2Semester/myconf5.txt deleted file mode 100644 index 0f3d05b..0000000 --- a/2Semester/myconf5.txt +++ /dev/null @@ -1 +0,0 @@ -Firmenname = "dgfgfeg"Firmenadresse = "sfsfw"Bankverbindung ="eafedfw" \ No newline at end of file diff --git a/2Semester/myconf6.txt b/2Semester/myconf6.txt deleted file mode 100644 index 52f584b..0000000 --- a/2Semester/myconf6.txt +++ /dev/null @@ -1,3 +0,0 @@ -Firmenname = "fhhfd" -Firmenadresse = "r4ffed" -Bankverbindung ="4rfe224" diff --git a/2Semester/src/fakturierungssystem/Datenmodell.java b/2Semester/src/fakturierungssystem/Datenmodell.java index bf580fa..94bb039 100644 --- a/2Semester/src/fakturierungssystem/Datenmodell.java +++ b/2Semester/src/fakturierungssystem/Datenmodell.java @@ -2,26 +2,63 @@ package fakturierungssystem; public class Datenmodell { private String firmenname; - private String firmenadresse; + private String strasse; + private String hausnummer; + private int plz; + private String wohnort; + private String land; private String bankverbindung; - + private int steuerid; + + + public String getFirmenname() { return firmenname; } public void setFirmenname(String firmenname) { this.firmenname = firmenname; } - public String getFirmenadresse() { - return firmenadresse; - } - public void setFirmenadresse(String firmenadresse) { - this.firmenadresse = firmenadresse; - } public String getBankverbindung() { return bankverbindung; } public void setBankverbindung(String bankverbindung) { this.bankverbindung = bankverbindung; } + public String getStrasse() { + return strasse; + } + public void setStrasse(String strasse) { + this.strasse = strasse; + } + public String getHausnummer() { + return hausnummer; + } + public void setHausnummer(String hausnummer) { + this.hausnummer = hausnummer; + } + public int getPlz() { + return plz; + } + public void setPlz(int plz) { + this.plz = plz; + } + public String getWohnort() { + return wohnort; + } + public void setWohnort(String wohnort) { + this.wohnort = wohnort; + } + public String getLand() { + return land; + } + public void setLand(String land) { + this.land = land; + } + public int getSteuerid() { + return steuerid; + } + public void setSteuerid(int steuerid) { + this.steuerid = steuerid; + } } diff --git a/2Semester/src/fakturierungssystem/Persistierung.java b/2Semester/src/fakturierungssystem/Persistierung.java index 0562e30..111a194 100644 --- a/2Semester/src/fakturierungssystem/Persistierung.java +++ b/2Semester/src/fakturierungssystem/Persistierung.java @@ -1,33 +1,48 @@ package fakturierungssystem; +import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; +import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class Persistierung { - private static String cfgFile; - File tempFile = new File(cfgFile); - boolean exists = tempFile.exists(); + private static String cfgFile = "myconf.cfg"; +; BufferedWriter file; - - { - if (exists == false) { - try (BufferedWriter file = new BufferedWriter(new FileWriter(cfgFile))) { - } catch (IOException e) { - e.printStackTrace(); - } - } - - } + Datenmodell dm; + + public Persistierung() { + dm = new Datenmodell(); + } + +public void read() { + try (BufferedReader file = new BufferedReader(new FileReader(cfgFile))) { + System.out.println(file.readLine()); + dm.setFirmenname(file.readLine()); +// dm.setFirmenname(dm.getFirmenname().substring(dm.getFirmenname().indexOf(delimiter) + 1, +// dm.getFirmenname().lastIndexOf(delimiter))); + dm.setBankverbindung(file.readLine()); +// dm.setBankverbindung(dm.getBankverbindung().substring(dm.getBankverbindung().indexOf(delimiter) + 1, dm.getBankverbindung().lastIndexOf(delimiter))); + System.out.println("Firma: " + dm.getFirmenname()); + System.out.println("Bank: " + dm.getBankverbindung()); + } catch (IOException e) { + + } +} + public void write(String satz) { try { + FileWriter file = new FileWriter(cfgFile); file.write(satz); + file.close(); } catch (IOException e) { e.printStackTrace(); } } + public void close() { try { file.close(); diff --git a/2Semester/src/fakturierungssystem/UI.java b/2Semester/src/fakturierungssystem/UI.java index c8599b2..1e38f8e 100644 --- a/2Semester/src/fakturierungssystem/UI.java +++ b/2Semester/src/fakturierungssystem/UI.java @@ -1,24 +1,49 @@ package fakturierungssystem; +import java.io.File; import java.util.*; public class UI { - public static void main(String[] args) { - System.out.println("Willkommen!"); + public static void main(String[] args) { + System.out.println("Willkommen!"); Scanner sc = new Scanner(System.in); Persistierung ps = new Persistierung(); - System.out.println("Firmenname:"); - String firma = sc.nextLine(); - char quote = '"'; - ps.write("Firmenname = " + quote + firma + quote + "\n"); - System.out.println("Firmenadresse: "); - String adresse = sc.nextLine(); - ps.write("Firmenadresse = " + quote + adresse + quote + "\n"); - System.out.println("Bankverbindung: "); - String bank = sc.nextLine(); - ps.write("Bankverbindung =" + quote + bank + quote + "\n"); - System.out.println("Datei erfolgreich gespeichert"); - ps.close(); + Datenmodell dm = new Datenmodell(); + String cfgFile = "myconf.cfg"; + + File tempFile = new File(cfgFile); + if (!tempFile.exists()) { + System.out.println("Firmenname:"); + dm.setFirmenname(sc.nextLine()); + char quote = '"'; + ps.write("Firmenname = " + quote + dm.getFirmenname() + quote + "\n"); + System.out.println("Strasse = "); + dm.setStrasse(sc.nextLine()); + ps.write("Firmenadresse = " + quote + dm.getStrasse() + quote + "\n"); + System.out.println("Hausnummer = "); + dm.setHausnummer(sc.nextLine()); + ps.write("Hausnummer = " + quote + dm.getHausnummer() + quote + "\n"); + System.out.println("PLZ = "); + dm.setPlz(sc.nextInt()); + ps.write("PLZ = " + quote + dm.getPlz() + quote + "\n"); + System.out.println("Wohnort = "); + dm.setWohnort(cfgFile); + ps.write("Strasse = " + quote + dm.getWohnort() + quote + "\n"); + System.out.println("Land = "); + dm.setLand(sc.nextLine()); + ps.write("Land = " + quote + dm.getLand() + quote + "\n"); + System.out.println("Bankverbindung: "); + dm.setBankverbindung(sc.nextLine()); + ps.write("Bankverbindung =" + quote + dm.getBankverbindung() + quote + "\n"); + System.out.println("SteuerID = "); + dm.setSteuerid(sc.nextInt()); + ps.write("SteuerID = " + quote + dm.getSteuerid() + quote + "\n"); + System.out.println("Datei erfolgreich gespeichert"); + ps.close(); + + } else { + ps.read(); + } } diff --git a/2Semester/src/indexverwaltung/Datei.java b/2Semester/src/indexverwaltung/Datei.java index efdc5f7..dda15e7 100644 --- a/2Semester/src/indexverwaltung/Datei.java +++ b/2Semester/src/indexverwaltung/Datei.java @@ -3,41 +3,88 @@ package indexverwaltung; import java.io.*; public class Datei { -private int aktuell; -private String dateiname; -private int SATZLAENGE; -private RandomAccessFile eineStammdatei; + private int aktuell; + private String dateiname = "Indexdatei.txt"; + private int SATZLAENGE = 100; + private RandomAccessFile eineStammdatei; + public Datei() { -public void speichereSatz(String satz, int index) { - -} + } -public String leseSatz(int index) { - return null; -} + public Datei(String dateiname, int satzlänge) { + SATZLAENGE = satzlänge; + } -public void öffneDatei(String name) { - - -} + public void speichereSatz(String satz, int index) { + try { + positioniereAufSatz(index); + writeFixedString(satz, SATZLAENGE); -public void schliesseDatei() { - -} -public int gibAnzahlDatensätze() { - return 0; -} + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } -private void positioniereAufSatz(int index) { - -} + public String leseSatz(int index) { + try { + positioniereAufSatz(index); -private String readFixedString (int länge) { - return null; -} + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return readFixedString(SATZLAENGE); -private void writeFixedString (String einDatensatz, int länge) { - -} + } + + public void öffneDatei(String name) { + if (!name.isBlank()) + dateiname = name; + try { + eineStammdatei = new RandomAccessFile(dateiname, "rw"); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void schliesseDatei() { + try { + eineStammdatei.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public int gibAnzahlDatensätze() { + + return aktuell; + } + + private void positioniereAufSatz(int index) throws IOException { + eineStammdatei.seek(index * SATZLAENGE); + } + + private String readFixedString(int länge) { + StringBuffer satz = new StringBuffer(); + try { + while (länge-- > 0) + satz.append(eineStammdatei.readChar()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return satz.toString(); + } + + private void writeFixedString(String einDatensatz, int länge) { + StringBuffer sb = new StringBuffer(einDatensatz); + while (sb.length() != länge) + sb.append("\0"); + + } } diff --git a/2Semester/src/indexverwaltung/IndexUI.java b/2Semester/src/indexverwaltung/IndexUI.java index 5fd70c2..dde774c 100644 --- a/2Semester/src/indexverwaltung/IndexUI.java +++ b/2Semester/src/indexverwaltung/IndexUI.java @@ -1,17 +1,15 @@ package indexverwaltung; +import java.util.*; import java.io.*; import java.util.*; public class IndexUI { - Scanner sc = new Scanner(System.in); - static File tempFile = new File("Datei.txt"); - static boolean exists = tempFile.exists(); public static void main(String[] args) { - System.out.println("Willkommen! "); -//wenn keine Datei existiert - + Scanner sc = new Scanner(System.in); + File tempFile = new File("Datei.txt"); + boolean exists = tempFile.exists(); if (exists == false) { try (BufferedWriter file = new BufferedWriter(new FileWriter("Datei.txt"))) { @@ -19,6 +17,27 @@ public class IndexUI { // TODO Auto-generated catch block e.printStackTrace(); } + Datei datei = new Datei(); + Index index = new Index(); + System.out.println("Willkommen bei der Indexverwaltung: "); +//wenn keine Datei existiert + try { + index.ladeIndexDatei(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println("Datei lesen (j) oder Datei schreiben (n)"); + String eingabe; + do { + eingabe = sc.nextLine(); + } while (!(eingabe.equals("j")) || !(eingabe.equals("n"))); + if (eingabe.equals("j")) { + + } else { + + } + }