ArrayListe für die ProduktObjekte

main
Laura Kalkbrenner 2025-12-13 19:35:06 +01:00
parent 283aecb926
commit ac600c48cc
45 changed files with 112 additions and 37 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,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CatActivitySettingProjectState">
<option name="details" value="File" />
<option name="enabled" value="true" />
<option name="fileDetailFormat" value="Online Shop (%branch%)" />
<option name="firstInit" value="false" />
<option name="idleDetailFormat" value="Online Shop (%branch%)" />
<option name="theme" value="Frappe" />
</component>
</project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
<option name="nameOverrideEnabled" value="true" />
<option name="nameOverrideText" value="Online Shop" />
<option name="description" value="" />
</component>
</project>

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>

View File

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

View File

@ -5,63 +5,57 @@ import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class OnlineShop {
private static ArrayList<String> LagerList;
public static void Start() throws FileNotFoundException {
LagerList=readFile();
new OnlineShop(LagerList);
}
public OnlineShop(ArrayList Lagerlist) throws FileNotFoundException {
String [][] produkt= produktListe(Lagerlist);
IO.print("");
for(int j=0;j<produkt[0].length;j++) {
IO.print(produkt[0][j]+" | ");
}
IO.println();
for(int i=0;i<produkt.length;i++) {
for(int j=0;j<produkt[i].length;j++) {
String helpString=produkt[i][j];
int length=10;
if(j==1)
length=25;
while(helpString.length()!=length){
helpString+=" ";
}
IO.print(helpString);
IO.print(" | ");
}
IO.println();
}
// TODO: Hier sollte die Produktliste geladen werden, vgl. Sudoku
}
public String[][] produktListe(ArrayList Lagerlist) throws FileNotFoundException {
public String[][] produktArray(ArrayList Lagerlist) throws FileNotFoundException {
LagerList= readFile();
String[] Lager = new String[LagerList.size()];
for (int i = 0; i < LagerList.size(); i++){
Lager[i] = LagerList.get(i);
}
String[][] produkt = new String[LagerList.size()][6];
String[][] produktArray = new String[LagerList.size()][6];
for(int i=0;i<Lager.length;i++) {
String[] HilfsArr= Lager[i].split(","); // Um es ähnlich wie beim Sudoku zu machen
for(int j=0;j<HilfsArr.length;j++) {
produkt[i][j]=HilfsArr[j];
produktArray[i][j]=HilfsArr[j];
if(i==0&&j==2)
produkt[i][j]="Gewicht"; //besser für den Druck
produkt[0][HilfsArr.length-1]="Bestand";
produktArray[i][j]="Gewicht"; //besser für den Druck
produktArray[0][HilfsArr.length-1]="Bestand";
}
}
return produkt;
return produktArray;
}
public static ArrayList<Produkt> erstelleListe(String[][] produktArray) {
ArrayList<Produkt> ProduktListe= new ArrayList<>();
for(int i=1;i<produktArray.length;i++) {
int ID = Integer.parseInt(produktArray[i][0]);
String name = produktArray[i][1];
double Gewicht = Double.parseDouble(produktArray[i][2]);
double nettopreis = Double.parseDouble(produktArray[i][3]);
double mwst = Double.parseDouble(produktArray[i][4]);
int Bestand = Integer.parseInt(produktArray[i][5]);
Produkt produkt = new Produkt(ID, name, Gewicht, nettopreis, mwst, Bestand);
ProduktListe.add(produkt);
//Ich hab jetzt ein ArrayListe für die Objekte erschaffen, vlt hätte ich das 2D Array nicht gebraucht,
//Ich hab mich jedoch dazu entschieden es erstmals so zulassen und eventuel später zu überarbeiten
}
return ProduktListe;
}
public static ArrayList<String> readFile() throws FileNotFoundException {
Scanner sc = new Scanner(new File("Shop/resources/produkte.csv"));
Scanner sc = new Scanner(new File("Shop/resources/produkte.csv")); //Vom Sudoku übernommen
ArrayList<String> LagerList = new ArrayList<>();
while (sc.hasNextLine()) {
LagerList.add(sc.nextLine());

View File

@ -4,11 +4,19 @@ public class Produkt {
String name;
double preis;
double mwst;
int ID;
double Gewicht;
int Bestand;
public Produkt(String name, double preis,double mwst) {
public Produkt(int ID,String name, double Gewicht, double preis,double mwst, int Bestand) {
this.name = name;
this.preis = preis;
this.mwst= mwst;
this.Gewicht=Gewicht;
this.Bestand=Bestand;
this.ID=ID;
}
public String toString() {
@ -17,6 +25,9 @@ public class Produkt {
public double berechneMwst(){
return Math.round((this.preis-(this.preis/(1+this.mwst/100)))*100.0)/100.0;
}
public double berechneBrutto(){
return preis-berechneMwst();
}
public boolean equals(Object o) {
if (!(o instanceof Produkt))

View File

@ -22,8 +22,6 @@ public class ShopTUI {
}
public static boolean hauptmenü() throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
String eingabe = sc.nextLine();
// TODO: hier ein erstes Menü mit bspw.
IO.println(" << H a u p t m e n ü >> ");
IO.println("1.Produktangebot");
@ -31,6 +29,8 @@ public class ShopTUI {
IO.println("3.Mein Warenkorb");
IO.println("4. Bestellungen");
IO.println("5. Exit ");
Scanner sc = new Scanner(System.in);
String eingabe = sc.nextLine();
if(eingabe.equalsIgnoreCase("Produktangebot") || eingabe.equalsIgnoreCase("1"))
produktangebot();
else if (eingabe.equalsIgnoreCase("Produktsuche")|| eingabe.equalsIgnoreCase("2")){

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.

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.