Beispiele aus der Vorlesung zum weiterarbeiten

main
Laura Kalkbrenner 2025-12-10 16:37:50 +01:00
parent e3a9b13e7d
commit f4934bfa4f
42 changed files with 229 additions and 0 deletions

8
.idea/.gitignore vendored 100644
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<MTProjectMetadataState>
<option name="migrated" value="true" />
<option name="pristineConfig" value="false" />
<option name="userId" value="5a5d4bcc:19b08ae5b2a:-7ffd" />
</MTProjectMetadataState>
</option>
</component>
</project>

6
.idea/misc.xml 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="25" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

10
.idea/modules.xml 100644
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/PR1.Online-Shop.iml" filepath="$PROJECT_DIR$/.idea/PR1.Online-Shop.iml" />
<module fileurl="file://$PROJECT_DIR$/Resource/Resource.iml" filepath="$PROJECT_DIR$/Resource/Resource.iml" />
<module fileurl="file://$PROJECT_DIR$/Shop/Shop.iml" filepath="$PROJECT_DIR$/Shop/Shop.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

11
Shop/Shop.iml 100644
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,8 @@
ProdId,Name,TransportGewicht,Netto,MwStSatz,Lagerbestand
1,Riesling 0.7 l,1.2,4.20,19,87
2,Pfälzer Saumagen 250 g,0.28,2.52,7,23
3,Gewürznelken 100 St.,0.01,2.52,7,3
4,Kokosmilch 250 ml,0.275,1.67,7,12
5,Bratwurst grob 250 g,0.258,2.09,7,17
6,Traubensaft 1.0 l,1.5,2.93,19,1
7,Gieskanne,0.2,3.80,19,13
1 ProdId Name TransportGewicht Netto MwStSatz Lagerbestand
2 1 Riesling 0.7 l 1.2 4.20 19 87
3 2 Pfälzer Saumagen 250 g 0.28 2.52 7 23
4 3 Gewürznelken 100 St. 0.01 2.52 7 3
5 4 Kokosmilch 250 ml 0.275 1.67 7 12
6 5 Bratwurst grob 250 g 0.258 2.09 7 17
7 6 Traubensaft 1.0 l 1.5 2.93 19 1
8 7 Gieskanne 0.2 3.80 19 13

View File

@ -0,0 +1,22 @@
package pack;
import java.util.ArrayList;
public class OnlineShop {
private ArrayList<Produkt> lager;
public OnlineShop() {
lager = new ArrayList<Produkt>();
// TODO: Hier sollte die Produktliste geladen werden, vgl. Sudoku
lager.add(new Produkt("Wein", 4.99));
}
public String[] produktListe() {
String[] produkt = new String[lager.size()];
for (int i = 0; i < lager.size(); i++)
produkt[i] = lager.get(i).toString();
return produkt;
}
}

View File

@ -0,0 +1,26 @@
package pack;
public class Produkt {
String name;
double preis;
public Produkt(String name, double preis) {
this.name = name;
this.preis = preis;
}
public String toString() {
return this.name + " " + this.preis + " Euro.";
}
public boolean equals(Object o) {
if (!(o instanceof Produkt))
return false;
if (!this.name.equals(((Produkt)o).name)
|| this.preis != ((Produkt)o).preis)
return false;
return true;
}
}

View File

@ -0,0 +1,26 @@
package pack;
import java.util.ArrayList;
public class Warenkorb {
private ArrayList<Produkt> inhalt;
public Warenkorb() {
inhalt = new ArrayList<Produkt>();
}
public void produktHinzufügen(Produkt p) {
inhalt.add(p);
}
public double berechneGesamtpreis() {
double preis = 0;
for (Produkt p : inhalt)
preis+= p.preis;
return preis;
}
}

View File

@ -0,0 +1,37 @@
package pack;
public class ShopTUI {
private static OnlineShop shop;
public static void main(String[] args) {
System.out.println("Willkommen beim THMA SuperStore!");
shop = new OnlineShop();
// TODO: Hauptmenü aufrufen, am besten in einer Schleife
produktangebot(); // nur als Beispiel, bitte hier entfernen
System.out.println("Auf Wiedersehen!");
}
public static void hauptmenü() {
// TODO: hier ein erstes Menü mit bspw.
// Produktangebot
// Produktsuche
// Warenkorbanzeige
// evtl. Bestellung (kann auch über Warenkorb realisiert werden)
// Exit
}
public static void produktangebot() {
System.out.println("Unser Produktangebot:");
System.out.println();
String[] produkte = shop.produktListe();
for (int i = 0; i < produkte.length; i++)
System.out.println((i+1) + ". " + produkte[i]);
}
}

View File

@ -0,0 +1,7 @@
package pack;
import static org.junit.jupiter.api.Assertions.*;
class OnlineShopTest {
}

View File

@ -0,0 +1,20 @@
package pack;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class ProduktTest {
@Test
void testGesamtPreis() {
Produkt p1 = new Produkt("Wein", 4.99);
Produkt p2 = new Produkt("Wasser", 0.7);
Warenkorb wk = new Warenkorb();
wk.produktHinzufügen(p1);
wk.produktHinzufügen(p2);
assertEquals(5.69, wk.berechneGesamtpreis(), 0.001);
}
}

View File

@ -0,0 +1,21 @@
package pack;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class WarenkorbTest {
@Test
void testGesamtPreis() {
Produkt p1 = new Produkt("Wein", 4.99);
Produkt p2 = new Produkt("Wasser", 0.7);
Warenkorb wk = new Warenkorb();
wk.produktHinzufügen(p1);
wk.produktHinzufügen(p2);
assertEquals(5.69, wk.berechneGesamtpreis(), 0.001);
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.