From 035ed242959a717948257773bd9a7d607d75749a Mon Sep 17 00:00:00 2001 From: Aminos061 <121253097+Aminos061@users.noreply.github.com> Date: Tue, 11 Jun 2024 16:33:42 +0200 Subject: [PATCH] amin first commit --- .gitignore | 17 + KI_Projekt/.gitignore | 1 + .../org.eclipse.core.resources.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 14 + KI_Projekt/src/Company.java | 62 ++++ KI_Projekt/src/Customer.java | 46 +++ KI_Projekt/src/DataManager.java | 347 ++++++++++++++++++ KI_Projekt/src/DeliveryNote.java | 46 +++ KI_Projekt/src/Invoice.java | 46 +++ KI_Projekt/src/Main.java | 8 + KI_Projekt/src/Offer.java | 63 ++++ KI_Projekt/src/OrderConfirmation.java | 46 +++ KI_Projekt/src/Product.java | 47 +++ KI_Projekt/src/XMLUtils.java | 48 +++ KI_Projekt/xml_data/customer_das.xml | 9 + KI_Projekt/xml_data/offer_1.xml | 12 + KI_Projekt/xml_data/product_ham.xml | 15 + 17 files changed, 829 insertions(+) create mode 100644 .gitignore create mode 100644 KI_Projekt/.gitignore create mode 100644 KI_Projekt/.settings/org.eclipse.core.resources.prefs create mode 100644 KI_Projekt/.settings/org.eclipse.jdt.core.prefs create mode 100644 KI_Projekt/src/Company.java create mode 100644 KI_Projekt/src/Customer.java create mode 100644 KI_Projekt/src/DataManager.java create mode 100644 KI_Projekt/src/DeliveryNote.java create mode 100644 KI_Projekt/src/Invoice.java create mode 100644 KI_Projekt/src/Main.java create mode 100644 KI_Projekt/src/Offer.java create mode 100644 KI_Projekt/src/OrderConfirmation.java create mode 100644 KI_Projekt/src/Product.java create mode 100644 KI_Projekt/src/XMLUtils.java create mode 100644 KI_Projekt/xml_data/customer_das.xml create mode 100644 KI_Projekt/xml_data/offer_1.xml create mode 100644 KI_Projekt/xml_data/product_ham.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a8f0ca1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar + +# Eclipse m2e generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath \ No newline at end of file diff --git a/KI_Projekt/.gitignore b/KI_Projekt/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/KI_Projekt/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/KI_Projekt/.settings/org.eclipse.core.resources.prefs b/KI_Projekt/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/KI_Projekt/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/KI_Projekt/.settings/org.eclipse.jdt.core.prefs b/KI_Projekt/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8c9943d --- /dev/null +++ b/KI_Projekt/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/KI_Projekt/src/Company.java b/KI_Projekt/src/Company.java new file mode 100644 index 0000000..bd66ae8 --- /dev/null +++ b/KI_Projekt/src/Company.java @@ -0,0 +1,62 @@ +import java.io.Serializable; + +public class Company implements Serializable{ + private String name; + private String address; + private String phone; + private String email; + private boolean isSmallBusiness; + + public Company() { + } + public Company(String name, String address, String phone, String email, boolean isSmallBusiness) { + this.name = name; + this.address = address; + this.phone = phone; + this.email = email; + this.isSmallBusiness = isSmallBusiness; + } + + // Getter und Setter + + @Override + public String toString() { + return "Company{" + + "name='" + name + '\'' + + ", address='" + address + '\'' + + ", phone='" + phone + '\'' + + ", email='" + email + '\'' + + ", isSmallBusiness=" + isSmallBusiness + + '}'; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getAddress() { + return address; + } + public void setAddress(String address) { + this.address = address; + } + public String getPhone() { + return phone; + } + public void setPhone(String phone) { + this.phone = phone; + } + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + public boolean isSmallBusiness() { + return isSmallBusiness; + } + public void setSmallBusiness(boolean isSmallBusiness) { + this.isSmallBusiness = isSmallBusiness; + } +} diff --git a/KI_Projekt/src/Customer.java b/KI_Projekt/src/Customer.java new file mode 100644 index 0000000..f6a0201 --- /dev/null +++ b/KI_Projekt/src/Customer.java @@ -0,0 +1,46 @@ +import java.io.Serializable; + +public class Customer implements Serializable { + private String address; + private String contactPerson; + private boolean smallBusiness; + + public Customer(String address, String contactPerson, boolean smallBusiness) { + this.address = address; + this.contactPerson = contactPerson; + this.smallBusiness = smallBusiness; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getContactPerson() { + return contactPerson; + } + + public void setContactPerson(String contactPerson) { + this.contactPerson = contactPerson; + } + + public boolean isSmallBusiness() { + return smallBusiness; + } + + public void setSmallBusiness(boolean smallBusiness) { + this.smallBusiness = smallBusiness; + } + + @Override + public String toString() { + return "Customer [address=" + address + ", contactPerson=" + contactPerson + ", smallBusiness=" + smallBusiness + + "]"; + } + + + // Getter und Setter +} diff --git a/KI_Projekt/src/DataManager.java b/KI_Projekt/src/DataManager.java new file mode 100644 index 0000000..0cfa5ad --- /dev/null +++ b/KI_Projekt/src/DataManager.java @@ -0,0 +1,347 @@ +import java.io.File; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Scanner; + +public class DataManager { + private List companies; + private List products; + private List customers; + private List offers; + private List orderConfirmations; + private List deliveryNotes; + private List invoices; + + public DataManager() { + this.companies = new ArrayList<>(); + this.products = new ArrayList<>(); + this.customers = new ArrayList<>(); + this.offers = new ArrayList<>(); + this.orderConfirmations = new ArrayList<>(); + this.deliveryNotes = new ArrayList<>(); + this.invoices = new ArrayList<>(); + } + public void showMenu() { + Scanner scanner = new Scanner(System.in); + int choice; + + do { + System.out.println("1. Neue Firma eingeben"); + System.out.println("2. Neues Produkt eingeben"); + System.out.println("3. Neuer Kunde eingeben"); + System.out.println("4. Angebot erstellen"); + System.out.println("5. Auftragsbestätigung erstellen"); + System.out.println("6. Lieferschein erstellen"); + System.out.println("7. Rechnung erstellen"); + System.out.println("8. Angebote anzeigen"); + System.out.println("9. Auftragsbestätigungen anzeigen"); + System.out.println("10. Lieferscheine anzeigen"); + System.out.println("11. Rechnungen anzeigen"); + System.out.println("12. Firmen anzeigen"); + System.out.println("13. Produkte anzeigen"); + System.out.println("14. Kunden anzeigen"); + System.out.println("15. XML-Daten laden"); + System.out.println("16. Beenden"); + System.out.print("Wählen Sie eine Option: "); + choice = scanner.nextInt(); + scanner.nextLine(); // Consume newline + + switch (choice) { + case 1: + enterCompany(scanner); + break; + case 2: + enterProduct(scanner); + break; + case 3: + enterCustomer(scanner); + break; + case 4: + createOffer(scanner); + break; + case 5: + createOrderConfirmation(scanner); + break; + case 6: + createDeliveryNote(scanner); + break; + case 7: + createInvoice(scanner); + break; + case 8: + displayOffers(); + break; + case 9: + displayOrderConfirmations(); + break; + case 10: + displayDeliveryNotes(); + break; + case 11: + displayInvoices(); + break; + case 12: + displayCompanies(); + break; + case 13: + displayProducts(); + break; + case 14: + displayCustomers(); + break; + case 15: + loadFromXML(); + System.out.println("XML-Daten erfolgreich geladen."); + break; + case 16: + System.out.println("Programm wird beendet."); + break; + default: + System.out.println("Ungültige Auswahl. Bitte erneut versuchen."); + } + } while (choice != 16); + } + public void enterCompany(Scanner scanner) { + System.out.print("Geben Sie den Firmennamen ein: "); + String name = scanner.nextLine(); + System.out.print("Geben Sie die Adresse ein: "); + String address = scanner.nextLine(); + System.out.print("Geben Sie die Telefonnummer ein: "); + String phone = scanner.nextLine(); + System.out.print("Geben Sie die E-Mail-Adresse ein: "); + String email = scanner.nextLine(); + System.out.print("Ist die Firma ein Kleinunternehmen? (ja/nein): "); + boolean isSmallBusiness = scanner.nextLine().equalsIgnoreCase("ja"); + + Company company = new Company(name, address, phone, email, isSmallBusiness); + companies.add(company); + XMLUtils.serializeObjectToXML( company, "xml_data/" + "company_" + name + ".xml"); + System.out.println("Firma erfolgreich hinzugefügt und in XML gespeichert."); + } + + public void enterProduct(Scanner scanner) { + System.out.print("Geben Sie die Einheit des Produkts ein: "); + String unit = scanner.nextLine(); + System.out.print("Geben Sie die Bezeichnung des Produkts ein: "); + String name = scanner.nextLine(); + System.out.print("Geben Sie den Nettopreis des Produkts ein: "); + double netPrice = Double.parseDouble(scanner.nextLine()); + System.out.print("Geben Sie den Mehrwertsteuersatz des Produkts ein: "); + double taxRate = Double.parseDouble(scanner.nextLine()); + + Product product = new Product(unit, name, netPrice, taxRate); + products.add(product); + XMLUtils.serializeObjectToXML(product, "xml_data/" + "product_" + name + ".xml"); + System.out.println("Produkt erfolgreich hinzugefügt und in XML gespeichert."); + } + + public void enterCustomer(Scanner scanner) { + System.out.print("Geben Sie die Adresse des Kunden ein: "); + String address = scanner.nextLine(); + System.out.print("Geben Sie den Ansprechpartner des Kunden ein: "); + String contactPerson = scanner.nextLine(); + System.out.print("Ist der Kunde ein Kleinunternehmen? (ja/nein): "); + boolean isSmallBusiness = scanner.nextLine().equalsIgnoreCase("ja"); + + Customer customer = new Customer(address, contactPerson, isSmallBusiness); + customers.add(customer); + XMLUtils.serializeObjectToXML(customer, "xml_data/" + "customer_" + contactPerson + ".xml"); + System.out.println("Kunde erfolgreich hinzugefügt und in XML gespeichert."); + } + public void createOffer(Scanner scanner) { + System.out.println("Neues Angebot erstellen:"); + displayCustomers(); + System.out.print("Wählen Sie einen Kunden aus (Index): "); + int customerIndex = scanner.nextInt(); + Customer customer = customers.get(customerIndex); + + // Eingabe des Datums durch den Benutzer + System.out.print("Geben Sie das Datum des Angebots ein (Format: dd-MM-yyyy): "); + String dateString = scanner.next(); + SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); + Date date = null; + try { + date = dateFormat.parse(dateString); + } catch (ParseException e) { + e.printStackTrace(); + } + int offerId = offers.size() + 1; + + Offer offer = new Offer(offerId, date, customer); // Hier wird das Datum gesetzt + + boolean addingProducts = true; + while (addingProducts) { + displayProducts(); + System.out.print("Wählen Sie ein Produkt aus (Index) oder -1 zum Beenden: "); + int productIndex = scanner.nextInt(); + if (productIndex == -1) { + addingProducts = false; + } else { + Product product = products.get(productIndex); + System.out.print("Geben Sie die Menge ein: "); + int quantity = scanner.nextInt(); + offer.addProduct(product, quantity); + } + } + + offers.add(offer); + System.out.println("Angebot erfolgreich erstellt."); + + // Angebot serialisieren + String offerFileName = "offer_" + offers.size() + ".xml"; + XMLUtils.serializeObjectToXML(offer, "xml_data/" + offerFileName); + System.out.println("Angebot als XML-Datei gespeichert: " + offerFileName); + } + + public void displayCompanies() { + System.out.println("Firmen:"); + for (Company company : companies) { + System.out.println(company); + } + } + + public void displayProducts() { + System.out.println("Produkte:"); + for (Product product : products) { + System.out.println(product); + } + } + + public void displayCustomers() { + System.out.println("Kunden:"); + for (Customer customer : customers) { + System.out.println(customer); + } + + } + public void displayOffers() { + System.out.println("Angebote:"); + for (int i = 0; i < offers.size(); i++) { + System.out.println("Angebot " + (i + 1) + ":"); + System.out.println(offers.get(i)); + } + if (offers.isEmpty()) { + System.out.println("Keine Angebote vorhanden."); + } + } + public void createOrderConfirmation(Scanner scanner) { + System.out.println("Neue Auftragsbestätigung erstellen:"); + displayOffers(); + System.out.print("Wählen Sie ein Angebot aus (Index): "); + int offerIndex = scanner.nextInt(); + Offer offer = offers.get(offerIndex); + + System.out.print("Geben Sie das Datum der Auftragsbestätigung ein (Format: dd-MM-yyyy): "); + String dateString = scanner.next(); + SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); + Date date = null; + try { + date = dateFormat.parse(dateString); + } catch (ParseException e) { + e.printStackTrace(); + } + int confirmationId = orderConfirmations.size() + 1; + + OrderConfirmation orderConfirmation = new OrderConfirmation(confirmationId, date, offer); + orderConfirmations.add(orderConfirmation); + System.out.println("Auftragsbestätigung erfolgreich erstellt."); + + // Auftragsbestätigung serialisieren + String confirmationFileName = "order_confirmation_" + orderConfirmations.size() + ".xml"; + XMLUtils.serializeObjectToXML(orderConfirmation, "xml_data/" + confirmationFileName); + System.out.println("Auftragsbestätigung als XML-Datei gespeichert: " + confirmationFileName); + } + + public void createDeliveryNote(Scanner scanner) { + System.out.println("Neuen Lieferschein erstellen:"); + displayOrderConfirmations(); + System.out.print("Wählen Sie eine Auftragsbestätigung aus (Index): "); + int confirmationIndex = scanner.nextInt(); + OrderConfirmation orderConfirmation = orderConfirmations.get(confirmationIndex); + + System.out.print("Geben Sie das Datum des Lieferscheins ein (Format: dd-MM-yyyy): "); + String dateString = scanner.next(); + SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); + Date date = null; + try { + date = dateFormat.parse(dateString); + } catch (ParseException e) { + e.printStackTrace(); + } + int deliveryNoteId = deliveryNotes.size() + 1; + + DeliveryNote deliveryNote = new DeliveryNote(deliveryNoteId, date, orderConfirmation); + deliveryNotes.add(deliveryNote); + System.out.println("Lieferschein erfolgreich erstellt."); + + // Lieferschein serialisieren + String deliveryNoteFileName = "delivery_note_" + deliveryNotes.size() + ".xml"; + XMLUtils.serializeObjectToXML(deliveryNote, "xml_data/" + deliveryNoteFileName); + System.out.println("Lieferschein als XML-Datei gespeichert: " + deliveryNoteFileName); + } + + public void createInvoice(Scanner scanner) { + System.out.println("Neue Rechnung erstellen:"); + displayDeliveryNotes(); + System.out.print("Wählen Sie einen Lieferschein aus (Index): "); + int deliveryNoteIndex = scanner.nextInt(); + DeliveryNote deliveryNote = deliveryNotes.get(deliveryNoteIndex); + + System.out.print("Geben Sie das Datum der Rechnung ein (Format: dd-MM-yyyy): "); + String dateString = scanner.next(); + SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); + Date date = null; + try { + date = dateFormat.parse(dateString); + } catch (ParseException e) { + e.printStackTrace(); + } + int invoiceId = invoices.size() + 1; + + Invoice invoice = new Invoice(invoiceId, date, deliveryNote); + invoices.add(invoice); + System.out.println("Rechnung erfolgreich erstellt."); + + // Rechnung serialisieren + String invoiceFileName = "invoice_" + invoices.size() + ".xml"; + XMLUtils.serializeObjectToXML(invoice, "xml_data/" + invoiceFileName); + System.out.println("Rechnung als XML-Datei gespeichert: " + invoiceFileName); + } + + public void displayOrderConfirmations() { + System.out.println("Auftragsbestätigungen:"); + for (int i = 0; i < orderConfirmations.size(); i++) { + System.out.println(i + ": " + orderConfirmations.get(i)); + } + } + + public void displayDeliveryNotes() { + System.out.println("Lieferscheine:"); + for (int i = 0; i < deliveryNotes.size(); i++) { + System.out.println(i + ": " + deliveryNotes.get(i)); + } + } + + public void displayInvoices() { + System.out.println("Rechnungen:"); + for (int i = 0; i < invoices.size(); i++) { + System.out.println(i + ": " + invoices.get(i)); + } + } + + public void loadFromXML() { + // Existierende Daten laden + companies = XMLUtils.deserializeObjectFromXML("xml_data/companies.xml"); + products = XMLUtils.deserializeObjectFromXML("xml_data/products.xml"); + customers = XMLUtils.deserializeObjectFromXML("xml_data/customers.xml"); + offers = XMLUtils.deserializeObjectFromXML("xml_data/offers.xml"); + orderConfirmations = XMLUtils.deserializeObjectFromXML("xml_data/order_confirmations.xml"); + deliveryNotes = XMLUtils.deserializeObjectFromXML("xml_data/delivery_notes.xml"); + invoices = XMLUtils.deserializeObjectFromXML("xml_data/invoices.xml"); + } + + +} diff --git a/KI_Projekt/src/DeliveryNote.java b/KI_Projekt/src/DeliveryNote.java new file mode 100644 index 0000000..b5c8a39 --- /dev/null +++ b/KI_Projekt/src/DeliveryNote.java @@ -0,0 +1,46 @@ +import java.util.Date; + +public class DeliveryNote { + private int deliveryNoteId; + private Date date; + private OrderConfirmation orderConfirmation; + + public DeliveryNote(int deliveryNoteId, Date date, OrderConfirmation orderConfirmation) { + this.deliveryNoteId = deliveryNoteId; + this.date = date; + this.orderConfirmation = orderConfirmation; + } + + public int getDeliveryNoteId() { + return deliveryNoteId; + } + + public void setDeliveryNoteId(int deliveryNoteId) { + this.deliveryNoteId = deliveryNoteId; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public OrderConfirmation getOrderConfirmation() { + return orderConfirmation; + } + + public void setOrderConfirmation(OrderConfirmation orderConfirmation) { + this.orderConfirmation = orderConfirmation; + } + + @Override + public String toString() { + return "DeliveryNote{" + + "deliveryNoteId=" + deliveryNoteId + + ", date=" + date + + ", orderConfirmation=" + orderConfirmation + + '}'; + } +} diff --git a/KI_Projekt/src/Invoice.java b/KI_Projekt/src/Invoice.java new file mode 100644 index 0000000..0015acb --- /dev/null +++ b/KI_Projekt/src/Invoice.java @@ -0,0 +1,46 @@ +import java.util.Date; + +public class Invoice { + private int invoiceId; + private Date date; + private DeliveryNote deliveryNote; + + public Invoice(int invoiceId, Date date, DeliveryNote deliveryNote) { + this.invoiceId = invoiceId; + this.date = date; + this.deliveryNote = deliveryNote; + } + + public int getInvoiceId() { + return invoiceId; + } + + public void setInvoiceId(int invoiceId) { + this.invoiceId = invoiceId; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public DeliveryNote getDeliveryNote() { + return deliveryNote; + } + + public void setDeliveryNote(DeliveryNote deliveryNote) { + this.deliveryNote = deliveryNote; + } + + @Override + public String toString() { + return "Invoice{" + + "invoiceId=" + invoiceId + + ", date=" + date + + ", deliveryNote=" + deliveryNote + + '}'; + } +} diff --git a/KI_Projekt/src/Main.java b/KI_Projekt/src/Main.java new file mode 100644 index 0000000..5c27cf7 --- /dev/null +++ b/KI_Projekt/src/Main.java @@ -0,0 +1,8 @@ + +public class Main { + public static void main(String[] args) { + DataManager manager = new DataManager(); + manager.showMenu(); + } +} + diff --git a/KI_Projekt/src/Offer.java b/KI_Projekt/src/Offer.java new file mode 100644 index 0000000..e46de0d --- /dev/null +++ b/KI_Projekt/src/Offer.java @@ -0,0 +1,63 @@ +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +public class Offer { + private int offerId; + private Date date; // Neues Date-Attribut für das Erstellungsdatum des Angebots + private Customer customer; + private Map products; + + public Offer(int offerId, Date date, Customer customer) { + this.offerId = offerId; + this.date = date; + this.customer = customer; + this.products = new HashMap<>(); + } + + public int getOfferId() { + return offerId; + } + + public void setOfferId(int offerId) { + this.offerId = offerId; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public Customer getCustomer() { + return customer; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + + public Map getProducts() { + return products; + } + + public void setProducts(Map products) { + this.products = products; + } + + public void addProduct(Product product, int quantity) { + products.put(product, quantity); + } + + @Override + public String toString() { + return "Offer{" + + "offerId=" + offerId + + ", date=" + date + + ", customer=" + customer + + ", products=" + products + + '}'; + } +} diff --git a/KI_Projekt/src/OrderConfirmation.java b/KI_Projekt/src/OrderConfirmation.java new file mode 100644 index 0000000..4ce7af1 --- /dev/null +++ b/KI_Projekt/src/OrderConfirmation.java @@ -0,0 +1,46 @@ +import java.util.Date; + +public class OrderConfirmation { + private int confirmationId; + private Date date; + private Offer offer; + + public OrderConfirmation(int confirmationId, Date date, Offer offer) { + this.confirmationId = confirmationId; + this.date = date; + this.offer = offer; + } + + public int getConfirmationId() { + return confirmationId; + } + + public void setConfirmationId(int confirmationId) { + this.confirmationId = confirmationId; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public Offer getOffer() { + return offer; + } + + public void setOffer(Offer offer) { + this.offer = offer; + } + + @Override + public String toString() { + return "OrderConfirmation{" + + "confirmationId=" + confirmationId + + ", date=" + date + + ", offer=" + offer + + '}'; + } +} diff --git a/KI_Projekt/src/Product.java b/KI_Projekt/src/Product.java new file mode 100644 index 0000000..71b62a2 --- /dev/null +++ b/KI_Projekt/src/Product.java @@ -0,0 +1,47 @@ +import java.io.Serializable; + +public class Product implements Serializable { + public static int getNextProductNumber() { + return nextProductNumber; + } + + public static void setNextProductNumber(int nextProductNumber) { + Product.nextProductNumber = nextProductNumber; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "Product [number=" + number + ", unit=" + unit + ", name=" + name + ", netPrice=" + netPrice + + ", taxRate=" + taxRate + "]"; + } + + private static int nextProductNumber = 1; + + private String number; + private String unit; + private String name; + private double netPrice; + private double taxRate; + + public Product(String unit, String name, double netPrice, double taxRate) { + this.number = generateProductNumber(); + this.unit = unit; + this.name = name; + this.netPrice = netPrice; + this.taxRate = taxRate; + } + + // Getter und Setter + + private String generateProductNumber() { + return "ART-" + nextProductNumber++; + } +} diff --git a/KI_Projekt/src/XMLUtils.java b/KI_Projekt/src/XMLUtils.java new file mode 100644 index 0000000..af50380 --- /dev/null +++ b/KI_Projekt/src/XMLUtils.java @@ -0,0 +1,48 @@ +import java.beans.XMLDecoder; +import java.beans.XMLEncoder; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.ArrayList; +import java.util.List; + +public class XMLUtils { + public static void serializeObjectToXML(Object obj, String filePath) { + try { + FileOutputStream fos = new FileOutputStream(filePath); + XMLEncoder encoder = new XMLEncoder(fos); + encoder.writeObject(obj); + encoder.close(); + fos.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static T deserializeObjectFromXML(String filePath) { + T obj = null; + try { + FileInputStream fis = new FileInputStream(filePath); + XMLDecoder decoder = new XMLDecoder(fis); + obj = (T) decoder.readObject(); + decoder.close(); + fis.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return obj; + } + + public static List deserializeListFromXML(String filePath) { + List list = new ArrayList<>(); + try { + FileInputStream fis = new FileInputStream(filePath); + XMLDecoder decoder = new XMLDecoder(fis); + list = (List) decoder.readObject(); + decoder.close(); + fis.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return list; + } +} diff --git a/KI_Projekt/xml_data/customer_das.xml b/KI_Projekt/xml_data/customer_das.xml new file mode 100644 index 0000000..468303f --- /dev/null +++ b/KI_Projekt/xml_data/customer_das.xml @@ -0,0 +1,9 @@ + + + address + Ahash + contactPerson + das + smallBusiness + true + diff --git a/KI_Projekt/xml_data/offer_1.xml b/KI_Projekt/xml_data/offer_1.xml new file mode 100644 index 0000000..320dede --- /dev/null +++ b/KI_Projekt/xml_data/offer_1.xml @@ -0,0 +1,12 @@ + + + offerId + 1 + date + + 1713736800000 + + customer + products + + diff --git a/KI_Projekt/xml_data/product_ham.xml b/KI_Projekt/xml_data/product_ham.xml new file mode 100644 index 0000000..394f9af --- /dev/null +++ b/KI_Projekt/xml_data/product_ham.xml @@ -0,0 +1,15 @@ + + + nextProductNumber + 2 + number + ART-1 + unit + mas + name + ham + netPrice + 122.0 + taxRate + 1.0 +