Add exercise 3

This commit is contained in:
Simon Giesel 2019-04-23 13:06:55 +02:00
parent 0a5ac00e5b
commit c98c024952
16 changed files with 307 additions and 0 deletions

6
.vscode/launch.json vendored
View file

@ -1,5 +1,11 @@
{
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - App",
"request": "launch",
"mainClass": "app.App"
},
{
"type": "java",
"name": "CodeLens (Launch) - App",

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<projectDescription>
<name>de.hhn.ai.prog2.blatt3.gui</name>
<comment/>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View file

@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch) - Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "Debug (Launch)-App<de.hhn.ai.prog2.blatt3.gui>",
"request": "launch",
"mainClass": "app.App",
"projectName": "de.hhn.ai.prog2.blatt3.gui"
}
]
}

View file

@ -0,0 +1,8 @@
package app;
public class App {
public static void main(String[] args) throws Exception {
MyFirstJFrame myfiFirstJFrame = new MyFirstJFrame();
myfiFirstJFrame.setVisible(true);
}
}

View file

@ -0,0 +1,51 @@
package app;
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
public class MyFirstJFrame extends JFrame {
private static final long serialVersionUID = -4444568389750643191L;
public MyFirstJFrame() {
super("Mein erstes Fenser :)");
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setBounds(100, 100, 400, 400);
Container container = this.getContentPane();
container.setLayout(new GridLayout(10, 2));
// container.setLayout(new GridBagLayout());
container.add(new JLabel("Bezeichner für Eingabefeld:"));
JTextField textField = new JTextField(20);
container.add(textField);
container.add(new JLabel("Bezeichner für Textfeld:"));
JTextArea textArea = new JTextArea();
textArea.setLineWrap(true);
textArea.setRows(2);
container.add(textArea);
JButton button = new JButton("Schaltfläche");
container.add(button);
container.add(new JLabel("Liste:"));
JList<String> list = new JList<String>(new String[] { "Option 1", "Option 2", "Option 3" });
container.add(list);
ButtonGroup buttonGroup = new ButtonGroup();
JRadioButton radioButton1 = new JRadioButton("weiblich");
buttonGroup.add(radioButton1);
container.add(radioButton1);
JRadioButton radioButton2 = new JRadioButton("männlich");
buttonGroup.add(radioButton2);
container.add(radioButton2);
JRadioButton radioButton3 = new JRadioButton("unbekannt");
buttonGroup.add(radioButton3);
container.add(radioButton3);
// this.pack();
}
}

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<projectDescription>
<name>de.hhn.ai.prog2.blatt3.pizzashop</name>
<comment/>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View file

@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch) - Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "Debug (Launch)-App<de.hhn.ai.prog2.blatt3.pizzashop>",
"request": "launch",
"mainClass": "app.App",
"projectName": "de.hhn.ai.prog2.blatt3.pizzashop"
}
]
}

View file

@ -0,0 +1,7 @@
package app;
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Hello Java");
}
}

View file

@ -0,0 +1,43 @@
package app;
import java.util.ArrayList;
import java.util.List;
public class Order {
private String id;
private boolean completed = false;
private List<Pizza> pizzas = new ArrayList<Pizza>();
public Order(List<Pizza> pizzas) {
this.id = "TODO:Random123";
this.pizzas = pizzas;
}
public String getId() {
return this.id;
}
public boolean isCompleted() {
return this.completed;
}
public List<Pizza> getPizzas() {
return this.pizzas;
}
public void addPizza(Pizza pizza) {
pizzas.add(pizza);
}
/**
* @param completed the completed to set
*/
public void setCompleted(boolean completed) {
this.completed = completed;
}
@Override
public String toString() {
return "Test"; // TODO:
}
}

View file

@ -0,0 +1,46 @@
package app;
import java.util.ArrayList;
import java.util.List;
public class Pizza {
private String name;
private PizzaSize size;
private List<Topping> toppings = new ArrayList<Topping>();
public Pizza(String name, PizzaSize pizzaSize, List<Topping> toppings) {
this.name = name;
this.size = pizzaSize;
this.toppings = toppings;
}
public String getName() {
return this.name;
}
public PizzaSize getSize() {
return this.size;
}
public List<Topping> getToppings() {
return this.toppings;
}
public int getPrice() {
int price = size.getPrice();
for (int i = 0; i < toppings.size(); i++) {
price += toppings.get(i).getPrice();
}
return price;
}
public void addTopping(Topping topping) {
toppings.add(topping);
}
@Override
public String toString() {
return "Test"; // TODO:
}
}

View file

@ -0,0 +1,22 @@
package app;
public enum PizzaSize {
SMALL(400, "klein"), MEDIUM(500, "mittel"), LARGE(600, "groß"), FAMILY(1000, "extra groß");
/** price in Cent */
private int price;
/** Name in german for UI */
private String name;
PizzaSize(int price, String name) {
this.price = price;
this.name = name;
}
public int getPrice() {
return this.price;
}
public String getName() {
return name;
}
}

View file

@ -0,0 +1,22 @@
package app;
public enum Topping {
CHEESE(50, "Käse"), TOMATO(25, "Tomate"), HAM(80, "Schinken"), MUSHROOM(40, "Champignon");
/** price in Cent */
private int price;
/** Name in german for UI */
private String name;
Topping(int price, String name) {
this.price = price;
this.name = name;
}
public int getPrice() {
return this.price;
}
public String getName() {
return name;
}
}