Grundgerüst (ShopTUI + Objekte OnlineShop, Warenkorb, Produkt und die jeweilige Struktur initialisieren)

main
igor.lewandowski 2025-12-10 20:37:15 +01:00
parent 8253853a0c
commit bb8f189652
7 changed files with 153 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,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>

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>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/OnlineShop.iml" filepath="$PROJECT_DIR$/.idea/OnlineShop.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>

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

106
src/ShopTUI.java 100644
View File

@ -0,0 +1,106 @@
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ShopTUI {
public static OnlineShop shop;
public static void main(String[] args) throws FileNotFoundException {
System.out.println("Willkommen im Lewandowski Store!");
shop = new OnlineShop();
produktangebot();
hauptmenu();
}
public static void hauptmenu() throws FileNotFoundException {
System.out.println("Was möchten Sie tun?");
System.out.println("(1=Produktsuche, 2=Warenkorbanzeige, 3=Bestellung abschließen, 0=Programm beenden): ");
while (true) {
Scanner scanner = new Scanner(System.in);
int wahl = scanner.nextInt();
switch (wahl) {
case 1:
produktsuche();
break;
case 2:
shop.warenkorbAusgabe();
break;
case 3:
break;
case 0:
System.exit(0);
break;
default: System.out.println("Falsche Eingabe!");
continue;
}
}
}
public static void produktangebot() throws FileNotFoundException {
System.out.println("Diese Produkte bieten wir an: ");
System.out.println("");
String[] produkte = shop.produkteListe();
for (int i = 0; i < produkte.length; i++) {
System.out.println(produkte[i]);
}
}
public static void produktsuche() throws FileNotFoundException {
while (true) {
System.out.println("Geben Sie das gewünschte Produkt mit der ProduktNr an");
System.out.println("(0 für erneute Anzeige der Produkte, " + (shop.lager.size() + 1) + " um zum Hauptmenü zurückzukehren)");
Scanner scanner = new Scanner(System.in);
int produktNr = scanner.nextInt();
if (produktNr == 0) {
produktangebot();
continue;
} else if (produktNr == shop.lager.size() + 1) {
break;
}
System.out.println("Meinen Sie dieses Produkt?");
System.out.println(shop.lager.get(produktNr - 1));
System.out.println("1=Ja, 2=Nein");
scanner = new Scanner(System.in);
int eingabe = scanner.nextInt();
if (eingabe == 1) {
System.out.println("Wie viele möchten Sie in Warenkorb legen?");
scanner = new Scanner(System.in);
int menge = scanner.nextInt();
System.out.println("Dieses Produkt " + menge + " mal in den Warenkorb legen? (1=Ja, 2=Nein)");
scanner = new Scanner(System.in);
while (true) {
eingabe = scanner.nextInt();
if (eingabe == 1) {
shop.inWarenkorb(produktNr, menge);
System.out.println("Möchten Sie ein weiteres Produkt hinzufügen? (1=Ja, 2=Nein)");
scanner = new Scanner(System.in);
eingabe = scanner.nextInt();
if (eingabe == 1) {
continue;
}
else if (eingabe == 2) {
hauptmenu();
}
else{ System.out.println("Probieren Sie es erneut");}
} else {
System.out.println("Probieren Sie es erneut.");
continue;
}
}
}
else if(eingabe == 2) {
continue;
}
else {
System.out.println("Probieren Sie es erneut.");
continue;
}
}
}
}