From 795bb4ac6332a62ce02658043cc9ea3239b66842 Mon Sep 17 00:00:00 2001 From: Simon Giesel Date: Tue, 30 Apr 2019 12:56:07 +0200 Subject: [PATCH] Add partial exercise 4 --- .../src/app/Adresse.java | 9 ++ .../src/app/App.java | 3 +- .../src/app/KontaktDaten.java | 8 + .../src/app/Kunde.java | 30 ++++ .../src/app/KundenService.java | 34 ++++ .../src/app/MyPizzaShop.java | 150 ++++++++++++++++++ 6 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 de.hhn.ai.prog2.blatt3.pizzashop/src/app/Adresse.java create mode 100644 de.hhn.ai.prog2.blatt3.pizzashop/src/app/KontaktDaten.java create mode 100644 de.hhn.ai.prog2.blatt3.pizzashop/src/app/Kunde.java create mode 100644 de.hhn.ai.prog2.blatt3.pizzashop/src/app/KundenService.java create mode 100644 de.hhn.ai.prog2.blatt3.pizzashop/src/app/MyPizzaShop.java diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Adresse.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Adresse.java new file mode 100644 index 0000000..fc4e9fb --- /dev/null +++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Adresse.java @@ -0,0 +1,9 @@ +package app; + +public class Adresse { + private int id; + private String street; + private int houseNumber; + private int zipCode; + private String place; +} \ No newline at end of file diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/App.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/App.java index 0518caa..c1ff1eb 100644 --- a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/App.java +++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/App.java @@ -2,6 +2,7 @@ package app; public class App { public static void main(String[] args) throws Exception { - System.out.println("Hello Java"); + MyPizzaShop myPizzaShop = new MyPizzaShop(); + myPizzaShop.setVisible(true); } } \ No newline at end of file diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/KontaktDaten.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/KontaktDaten.java new file mode 100644 index 0000000..dec829d --- /dev/null +++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/KontaktDaten.java @@ -0,0 +1,8 @@ +package app; + +public class KontaktDaten { + private int id; + private int tel; + private int mobile; + private String email; +} \ No newline at end of file diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Kunde.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Kunde.java new file mode 100644 index 0000000..6051d61 --- /dev/null +++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Kunde.java @@ -0,0 +1,30 @@ +package app; + +public class Kunde { + private int id; + private String lastName; + private String name; + private String sex; + private KontaktDaten kontaktDaten; + private Adresse address; + private Adresse shippingAddress; + + public int getId() { + return id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @return the lastName + */ + public String getLastName() { + return lastName; + } + +} \ No newline at end of file diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/KundenService.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/KundenService.java new file mode 100644 index 0000000..e6acfbf --- /dev/null +++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/KundenService.java @@ -0,0 +1,34 @@ +package app; + +import java.util.ArrayList; +import java.util.List; + +public class KundenService { + private List kunden = new ArrayList(); + + public void create(Kunde kunde) { + kunden.add(kunde); + } + + // public void update(); // TODO: + + public void delete(Kunde kunde) { + kunden.remove(kunde); + } + + public Kunde read(int id) { + for (Kunde kunde : kunden) { + if (kunde.getId() == id) + return kunde; + } + return null; + } + + public Kunde read(String name, String lastName) { + for (Kunde kunde : kunden) { + if (kunde.getName() == name && kunde.getLastName() == lastName) + return kunde; + } + return null; + } +} \ No newline at end of file diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/MyPizzaShop.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/MyPizzaShop.java new file mode 100644 index 0000000..2a1d85e --- /dev/null +++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/MyPizzaShop.java @@ -0,0 +1,150 @@ +package app; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.GridLayout; +import java.awt.Panel; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; + +public class MyPizzaShop extends JFrame { + private static final long serialVersionUID = -5421020006317002203L; + + private Container container; + + public MyPizzaShop() { + super("My Pizza Shop"); + this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + this.setSize(800, 600); + this.setJMenuBar(new MenuBar()); + container = this.getContentPane(); + container.setLayout(new BorderLayout()); + StatusPanel panel = new StatusPanel(); + container.add(panel, BorderLayout.SOUTH); + showCenterPanel(new CenterPanel()); + } + + public void showCenterPanel(JPanel panel) { + container.add(panel, BorderLayout.CENTER); + } + + private class StatusPanel extends JPanel { + private static final long serialVersionUID = -5777179157927719004L; + + private StatusPanel() { + this.setBorder(BorderFactory.createLineBorder(Color.black)); + JLabel label = new JLabel("Wilkommen"); + this.add(label); + } + } + + private class MenuBar extends JMenuBar { + private static final long serialVersionUID = 7457449847994117214L; + + private MenuBar() { + JMenu menu = new JMenu("Datei"); + JMenuItem quit = new JMenuItem("Beenden"); + quit.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + }); + JPanel panel = new JPanel(); + panel.add(new JLabel("Hallo, das ist ein Begrüßungstext")); + menu.add(panel); + menu.add(quit); + this.add(menu); + + JMenu configurator = new JMenu("Konfigurator"); + JMenuItem listPizzas = new JMenuItem("Zeige definierte Pizzen"); + JMenuItem createPizza = new JMenuItem("Konfiguriere Pizza"); + createPizza.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + container.setVisible(!container.isVisible()); + } + }); + configurator.add(listPizzas); + configurator.add(createPizza); + this.add(configurator); + + JMenu management = new JMenu("Verwaltung"); + JMenuItem listStaff = new JMenuItem("Liste der Mitarbeiter"); + management.add(listStaff); + this.add(management); + + JMenu customer = new JMenu("Kunden"); + JMenuItem listCustomer = new JMenuItem("Liste der Kunden"); + JMenuItem manageCustomer = new JMenuItem("Kunde bearbeiten"); + customer.add(listCustomer); + customer.add(manageCustomer); + this.add(customer); + + JMenu order = new JMenu("Bestellung"); + JMenuItem listOders = new JMenuItem("Liste der Bestellungen"); + order.add(listOders); + this.add(order); + } + } + + private class CenterPanel extends JPanel { + private static final long serialVersionUID = 3527260169526726295L; + private JLabel priceLabel = new JLabel(); + private int price = 200; + + private CenterPanel() { + this.setLayout(new GridLayout(5, 2)); + this.add(wrap(new JLabel("Name:"))); + this.add(wrap(new JTextField(20))); + this.add(wrap(new JLabel("Größe:"))); + String[] pizzaSizes = new String[EnumSet.allOf(PizzaSize.class).size()]; + int i = 0; + for (PizzaSize size : EnumSet.allOf(PizzaSize.class)) { + pizzaSizes[i++] = size.getName(); + } + this.add(wrap(new JList(pizzaSizes))); + this.add(wrap(new JLabel("Belag:"))); + String[] toppings = new String[EnumSet.allOf(Topping.class).size()]; + i = 0; + for (Topping topping : EnumSet.allOf(Topping.class)) { + toppings[i++] = topping.getName(); + } + this.add(wrap(new JList(toppings))); + this.add(wrap(new JPanel())); + this.add(wrap(priceLabel)); + this.add(wrap(new JButton("Abschicken"))); + this.add(wrap(new JButton("Ausdrucken"))); + setPrice(price); + } + + public void setPrice(int price) { + this.price = price; + priceLabel.setText("Preis: " + price + " Cent"); + } + + private JPanel wrap(Component comp) { + JPanel panel = new JPanel(); + panel.add(comp); + return panel; + } + } +} \ No newline at end of file