Compare commits
3 Commits
acb7881eb6
...
bcb5e225e2
Author | SHA1 | Date | |
---|---|---|---|
|
bcb5e225e2 | ||
|
430268ed97 | ||
|
949ad201d7 |
11
.editorconfig
Normal file
11
.editorconfig
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*.{ps1,java}]
|
||||||
|
charset = utf-8
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
end_of_line = lf
|
||||||
|
|
||||||
|
[*.java]
|
||||||
|
insert_final_newline = true
|
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# compiled class files.
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
|
||||||
|
# Visual Studio Code
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# output folders
|
||||||
|
**/output/
|
16
T01/Aufgabe04/Aufgabe04.java
Normal file
16
T01/Aufgabe04/Aufgabe04.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package T01.Aufgabe04;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Teil 1 / Aufgabe 4
|
||||||
|
*
|
||||||
|
* @author Sebastian Brosch
|
||||||
|
*/
|
||||||
|
class Aufgabe04 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Produkt mehl = new Produkt(1, "Mehl", 2.5, Regalnummer.Regal01);
|
||||||
|
mehl.print();
|
||||||
|
|
||||||
|
Produkt salz = new Produkt(2, "Salz", 3.5, Regalnummer.Regal02);
|
||||||
|
salz.print();
|
||||||
|
}
|
||||||
|
}
|
30
T01/Aufgabe04/Produkt.java
Normal file
30
T01/Aufgabe04/Produkt.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package T01.Aufgabe04;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List with all available shelf numbers.
|
||||||
|
*/
|
||||||
|
enum Regalnummer {
|
||||||
|
Regal01, Regal02, Regal03, Regal04, Regel05
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to represent a Produkt.
|
||||||
|
*/
|
||||||
|
public class Produkt {
|
||||||
|
int id;
|
||||||
|
String name;
|
||||||
|
double nettopreis;
|
||||||
|
Regalnummer regal;
|
||||||
|
|
||||||
|
Produkt(int id, String name, double nettopreis, Regalnummer regal) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.nettopreis = nettopreis;
|
||||||
|
this.regal = regal;
|
||||||
|
}
|
||||||
|
|
||||||
|
void print() {
|
||||||
|
System.out.printf("%d - %s: %.2f (%s)\n", this.id, this.name, this.nettopreis,
|
||||||
|
this.regal.toString());
|
||||||
|
}
|
||||||
|
}
|
44
T01/Aufgabe05/ArrayQueue.java
Normal file
44
T01/Aufgabe05/ArrayQueue.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package T01.Aufgabe05;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to represent a ArrayQueue (using an array).
|
||||||
|
*/
|
||||||
|
public class ArrayQueue {
|
||||||
|
private Produkt queue[] = new Produkt[100];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to add a product to the Queue.
|
||||||
|
*
|
||||||
|
* @param produkt The product to add.
|
||||||
|
*/
|
||||||
|
public void add(Produkt produkt) {
|
||||||
|
for (int i = 0; i < this.queue.length; i++) {
|
||||||
|
if (queue[i] == null) {
|
||||||
|
int j = i;
|
||||||
|
while (j > 0) {
|
||||||
|
queue[j] = queue[j - 1];
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
queue[0] = produkt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to take a product from the Queue.
|
||||||
|
*
|
||||||
|
* @return The product taken from the Queue.
|
||||||
|
*/
|
||||||
|
public Produkt take() {
|
||||||
|
Produkt produkt = queue[0];
|
||||||
|
|
||||||
|
for (int i = 0; i < queue.length; i++) {
|
||||||
|
if (queue[i] == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
queue[i] = queue[i + 1];
|
||||||
|
}
|
||||||
|
return produkt;
|
||||||
|
}
|
||||||
|
}
|
33
T01/Aufgabe05/Aufgabe05.java
Normal file
33
T01/Aufgabe05/Aufgabe05.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package T01.Aufgabe05;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Teil 1 / Aufgabe 5
|
||||||
|
*
|
||||||
|
* @author Sebastian Brosch
|
||||||
|
*/
|
||||||
|
public class Aufgabe05 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
System.out.println("\nQueue with Array:");
|
||||||
|
|
||||||
|
ArrayQueue queueA = new ArrayQueue();
|
||||||
|
queueA.add(new Produkt(1, "Salz", 10.0, Regalnummer.Regal01));
|
||||||
|
queueA.add(new Produkt(2, "Zucker", 15.0, Regalnummer.Regal02));
|
||||||
|
queueA.add(new Produkt(3, "Mehl", 10.0, Regalnummer.Regal03));
|
||||||
|
|
||||||
|
queueA.take().print();
|
||||||
|
queueA.take().print();
|
||||||
|
queueA.take().print();
|
||||||
|
|
||||||
|
System.out.println("\nQueue with List:");
|
||||||
|
|
||||||
|
ListQueue queueB = new ListQueue();
|
||||||
|
queueB.add(new Produkt(1, "Salz", 10.0, Regalnummer.Regal01));
|
||||||
|
queueB.add(new Produkt(2, "Zucker", 15.0, Regalnummer.Regal02));
|
||||||
|
queueB.add(new Produkt(3, "Mehl", 10.0, Regalnummer.Regal03));
|
||||||
|
|
||||||
|
queueB.take().print();
|
||||||
|
queueB.take().print();
|
||||||
|
queueB.take().print();
|
||||||
|
}
|
||||||
|
}
|
30
T01/Aufgabe05/ListQueue.java
Normal file
30
T01/Aufgabe05/ListQueue.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package T01.Aufgabe05;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to represent a Queue (using a List).
|
||||||
|
*/
|
||||||
|
public class ListQueue {
|
||||||
|
ArrayList<Produkt> queue = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to add a product to the Queue.
|
||||||
|
*
|
||||||
|
* @param produkt The product to add.
|
||||||
|
*/
|
||||||
|
public void add(Produkt produkt) {
|
||||||
|
queue.add(0, produkt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to take a product from the Queue.
|
||||||
|
*
|
||||||
|
* @return The product taken from the Queue.
|
||||||
|
*/
|
||||||
|
public Produkt take() {
|
||||||
|
Produkt produkt = queue.get(0);
|
||||||
|
queue.remove(0);
|
||||||
|
return produkt;
|
||||||
|
}
|
||||||
|
}
|
30
T01/Aufgabe05/Produkt.java
Normal file
30
T01/Aufgabe05/Produkt.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package T01.Aufgabe05;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List with all available shelf numbers.
|
||||||
|
*/
|
||||||
|
enum Regalnummer {
|
||||||
|
Regal01, Regal02, Regal03, Regal04, Regel05
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to represent a Produkt.
|
||||||
|
*/
|
||||||
|
public class Produkt {
|
||||||
|
int id;
|
||||||
|
String name;
|
||||||
|
double nettopreis;
|
||||||
|
Regalnummer regal;
|
||||||
|
|
||||||
|
Produkt(int id, String name, double nettopreis, Regalnummer regal) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.nettopreis = nettopreis;
|
||||||
|
this.regal = regal;
|
||||||
|
}
|
||||||
|
|
||||||
|
void print() {
|
||||||
|
System.out.printf("%d - %s: %.2f (%s)\n", this.id, this.name, this.nettopreis,
|
||||||
|
this.regal.toString());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user