auskommentiert, das einzige was fehlt ist, dass die Eingabedaten
wirklich in die Datei gespeichert werden, damit man alle auslesen kannmaster
parent
510b26edb7
commit
4448c76bf3
|
@ -1,17 +1,18 @@
|
||||||
package fakturierungssystem;
|
package fakturierungssystem;
|
||||||
|
|
||||||
public class Datenmodell {
|
public class Datenmodell {
|
||||||
|
// Deklarierung der Variablen
|
||||||
private String firmenname;
|
private String firmenname;
|
||||||
private String strasse;
|
private String strasse;
|
||||||
private String hausnummer;
|
private String hausnummer;
|
||||||
private int plz;
|
private String plz;
|
||||||
private String wohnort;
|
private String wohnort;
|
||||||
private String land;
|
private String land;
|
||||||
private String bankverbindung;
|
private String bankverbindung;
|
||||||
private int steuerid;
|
private String steuerid;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//getter und setter Methoden
|
||||||
public String getFirmenname() {
|
public String getFirmenname() {
|
||||||
return firmenname;
|
return firmenname;
|
||||||
}
|
}
|
||||||
|
@ -36,11 +37,11 @@ public class Datenmodell {
|
||||||
public void setHausnummer(String hausnummer) {
|
public void setHausnummer(String hausnummer) {
|
||||||
this.hausnummer = hausnummer;
|
this.hausnummer = hausnummer;
|
||||||
}
|
}
|
||||||
public int getPlz() {
|
public String getPlz() {
|
||||||
return plz;
|
return plz;
|
||||||
}
|
}
|
||||||
public void setPlz(int plz) {
|
public void setPlz(String string) {
|
||||||
this.plz = plz;
|
this.plz = string;
|
||||||
}
|
}
|
||||||
public String getWohnort() {
|
public String getWohnort() {
|
||||||
return wohnort;
|
return wohnort;
|
||||||
|
@ -54,10 +55,10 @@ public class Datenmodell {
|
||||||
public void setLand(String land) {
|
public void setLand(String land) {
|
||||||
this.land = land;
|
this.land = land;
|
||||||
}
|
}
|
||||||
public int getSteuerid() {
|
public String getSteuerid() {
|
||||||
return steuerid;
|
return steuerid;
|
||||||
}
|
}
|
||||||
public void setSteuerid(int steuerid) {
|
public void setSteuerid(String steuerid) {
|
||||||
this.steuerid = steuerid;
|
this.steuerid = steuerid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,47 +8,60 @@ import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Persistierung {
|
public class Persistierung {
|
||||||
private static String cfgFile = "myconf.cfg";
|
private static String cfgFile = "myconf.cfg"; // Name der Datei, static damit diese ohne Objekt da ist
|
||||||
;
|
|
||||||
BufferedWriter file;
|
|
||||||
Datenmodell dm;
|
Datenmodell dm;
|
||||||
|
BufferedWriter file;
|
||||||
|
|
||||||
public Persistierung() {
|
public Persistierung() {
|
||||||
dm = new Datenmodell();
|
dm = new Datenmodell(); //Instanziierung erst in Konstruktor, damit nur ein Datenmodellobjejt
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read() {
|
public void read() {//
|
||||||
try (BufferedReader file = new BufferedReader(new FileReader(cfgFile))) {
|
try (BufferedReader file = new BufferedReader(new FileReader(cfgFile))) {//Instanziierung br mit try/catch!!
|
||||||
System.out.println(file.readLine());
|
// System.out.println(file.readLine());
|
||||||
dm.setFirmenname(file.readLine());
|
dm.setFirmenname(file.readLine());//nur erste Line wird angezeigt, ka wieso, eig sollte jedes Attribut gelesen und angezeigt werden
|
||||||
|
System.out.println(dm.getFirmenname());
|
||||||
|
|
||||||
|
dm.setStrasse(file.readLine());
|
||||||
|
System.out.println(dm.getStrasse());
|
||||||
|
|
||||||
|
dm.setHausnummer(file.readLine());
|
||||||
|
dm.setPlz(file.readLine());
|
||||||
|
dm.setWohnort(file.readLine());
|
||||||
|
dm.setLand(file.readLine());
|
||||||
|
dm.setBankverbindung(file.readLine());
|
||||||
|
dm.setSteuerid(file.readLine());
|
||||||
|
|
||||||
// dm.setFirmenname(dm.getFirmenname().substring(dm.getFirmenname().indexOf(delimiter) + 1,
|
// dm.setFirmenname(dm.getFirmenname().substring(dm.getFirmenname().indexOf(delimiter) + 1,
|
||||||
// dm.getFirmenname().lastIndexOf(delimiter)));
|
// dm.getFirmenname().lastIndexOf(delimiter)));
|
||||||
dm.setBankverbindung(file.readLine());
|
|
||||||
// dm.setBankverbindung(dm.getBankverbindung().substring(dm.getBankverbindung().indexOf(delimiter) + 1, dm.getBankverbindung().lastIndexOf(delimiter)));
|
// dm.setBankverbindung(dm.getBankverbindung().substring(dm.getBankverbindung().indexOf(delimiter) + 1, dm.getBankverbindung().lastIndexOf(delimiter)));
|
||||||
System.out.println("Firma: " + dm.getFirmenname());
|
System.out.println(dm.getHausnummer());
|
||||||
System.out.println("Bank: " + dm.getBankverbindung());
|
System.out.println(dm.getPlz());
|
||||||
} catch (IOException e) {
|
System.out.println(dm.getWohnort());
|
||||||
|
System.out.println(dm.getLand());
|
||||||
|
System.out.println(dm.getBankverbindung());
|
||||||
|
System.out.println(dm.getSteuerid());
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void write(String satz) {
|
public void write(String satz) {
|
||||||
try {
|
try {
|
||||||
FileWriter file = new FileWriter(cfgFile);
|
file = new BufferedWriter(new FileWriter(cfgFile));// hier wird bw instanziiert mit try/catch
|
||||||
file.write(satz);
|
file.write(satz);
|
||||||
file.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
try {
|
try {//stream schließen
|
||||||
file.close();
|
file.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
e.getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package fakturierungssystem;
|
package fakturierungssystem;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class UI {
|
public class UI {
|
||||||
|
@ -9,40 +9,40 @@ public class UI {
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
Persistierung ps = new Persistierung();
|
Persistierung ps = new Persistierung();
|
||||||
Datenmodell dm = new Datenmodell();
|
Datenmodell dm = new Datenmodell();
|
||||||
String cfgFile = "myconf.cfg";
|
String cfgFile = "myconf.cfg";//name des Files
|
||||||
|
|
||||||
File tempFile = new File(cfgFile);
|
File tempFile = new File(cfgFile);
|
||||||
if (!tempFile.exists()) {
|
if (!tempFile.exists()) {//wenn Datei nicht da ist, soll jedes Attribut eingetragen werden
|
||||||
System.out.println("Firmenname:");
|
System.out.println("Firmenname:");
|
||||||
dm.setFirmenname(sc.nextLine());
|
dm.setFirmenname(sc.nextLine());
|
||||||
char quote = '"';
|
char quote = '"';
|
||||||
ps.write("Firmenname = " + quote + dm.getFirmenname() + quote + "\n");
|
ps.write("Firmenname = " + quote + dm.getFirmenname() + quote + "\n");
|
||||||
System.out.println("Strasse = ");
|
System.out.println("Strasse = ");
|
||||||
dm.setStrasse(sc.nextLine());
|
dm.setStrasse(sc.nextLine());
|
||||||
ps.write("Firmenadresse = " + quote + dm.getStrasse() + quote + "\n");
|
ps.write("Strasse = " + quote + dm.getStrasse() + quote + "\n");
|
||||||
System.out.println("Hausnummer = ");
|
System.out.println("Hausnummer = ");
|
||||||
dm.setHausnummer(sc.nextLine());
|
dm.setHausnummer(sc.nextLine());
|
||||||
ps.write("Hausnummer = " + quote + dm.getHausnummer() + quote + "\n");
|
ps.write("Hausnummer = " + quote + dm.getHausnummer() + quote + "\n");
|
||||||
System.out.println("PLZ = ");
|
System.out.println("PLZ = ");
|
||||||
dm.setPlz(sc.nextInt());
|
dm.setPlz(sc.nextLine());
|
||||||
ps.write("PLZ = " + quote + dm.getPlz() + quote + "\n");
|
ps.write("PLZ = " + quote + dm.getPlz() + quote + "\n");
|
||||||
System.out.println("Wohnort = ");
|
System.out.println("Wohnort = ");
|
||||||
dm.setWohnort(cfgFile);
|
dm.setWohnort(sc.nextLine());
|
||||||
ps.write("Strasse = " + quote + dm.getWohnort() + quote + "\n");
|
ps.write("Wohnort = " + quote + dm.getWohnort() + quote + "\n");
|
||||||
System.out.println("Land = ");
|
System.out.println("Land = ");
|
||||||
dm.setLand(sc.nextLine());
|
dm.setLand(sc.nextLine());
|
||||||
ps.write("Land = " + quote + dm.getLand() + quote + "\n");
|
ps.write("Land = " + quote + dm.getLand() + quote + "\n");
|
||||||
System.out.println("Bankverbindung: ");
|
System.out.println("Bankverbindung = ");
|
||||||
dm.setBankverbindung(sc.nextLine());
|
dm.setBankverbindung(sc.nextLine());
|
||||||
ps.write("Bankverbindung =" + quote + dm.getBankverbindung() + quote + "\n");
|
ps.write("Bankverbindung =" + quote + dm.getBankverbindung() + quote + "\n");
|
||||||
System.out.println("SteuerID = ");
|
System.out.println("SteuerID = ");
|
||||||
dm.setSteuerid(sc.nextInt());
|
dm.setSteuerid(sc.nextLine());
|
||||||
ps.write("SteuerID = " + quote + dm.getSteuerid() + quote + "\n");
|
ps.write("SteuerID = " + quote + dm.getSteuerid() + quote + "\n");
|
||||||
System.out.println("Datei erfolgreich gespeichert");
|
System.out.println("Datei erfolgreich gespeichert");
|
||||||
ps.close();
|
ps.close();//stream muss am Ende geschlossen werden!
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ps.read();
|
ps.read();//read-Methode wird bei Persistenz Klasse erläuert
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue