Compare commits

..

3 Commits

Author SHA1 Message Date
Sebastian Brosch
bcb5e225e2 added some basic files 2024-05-21 14:49:37 +02:00
Sebastian Brosch
430268ed97 Teil 1 / Aufgabe 4 2024-05-21 14:49:18 +02:00
Sebastian Brosch
949ad201d7 Teil 1 / Aufgabe 5 2024-05-21 14:48:00 +02:00
8 changed files with 206 additions and 0 deletions

11
.editorconfig Normal file
View 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
View File

@ -0,0 +1,12 @@
# compiled class files.
*.class
# IntelliJ
.idea/
*.iml
# Visual Studio Code
.vscode/
# output folders
**/output/

View 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();
}
}

View 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());
}
}

View 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;
}
}

View 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();
}
}

View 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;
}
}

View 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());
}
}