Package Struktur modifiziert

main
Daniel Zikol 2025-12-12 16:18:51 +01:00
parent 0b476fe37f
commit 06d1e9bc0c
20 changed files with 206 additions and 129 deletions

View File

@ -11,3 +11,6 @@ https://www.w3schools.com/java/java_encapsulation.asp
Code Gym - Get and Set
https://codegym.cc/de/groups/posts/getter-und-setter-in-java
Bro Code - How to read a File
https://www.youtube.com/watch?v=eHjbvgw4hsI

View File

@ -1,4 +1,9 @@
package shoppackage;
package shop;
public class Cart {
}

View File

@ -1,4 +1,4 @@
package shoppackage;
package shop;
/*
@ -6,13 +6,14 @@ Cart Pos speichert die Menge der Products ---> bekommt product und menge (quanti
*/
public class CartPosition {
//Produkt ist eine referenz auf Product
//Produkt ist eine referenz auf product
private Product product;
//Die menge der produkte die gekauft werden sollen
private int quantity;
public CartPosition(Product product, int quantity){
public CartPosition(Product product, int quantity) {
this.product = product;
this.quantity = quantity;
}
}

View File

@ -0,0 +1,46 @@
package shop;
/*
Controller Klasse des Projektes.
TODO
Lager bestand für ein x beliebiges product bauen ----> Herr Hummels ansatz aus VL ausarbeiten
Cart übergeben
Order klasse integrieren
Logik ---> Product suchen & Kauf abschluss?
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class OnlineShop {
ArrayList<Product> lager;
//ArrayList
public OnlineShop() {
lager = new ArrayList<Product>();
}
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;
}
public static ArrayList<String> readFile(String path) throws FileNotFoundException {
ArrayList<String> lines = new ArrayList<>();
Scanner sc = new Scanner(new File(path));
while (sc.hasNextLine()) {
lines.add(sc.nextLine());
}
sc.close();
return lines;
}
}

View File

@ -0,0 +1,6 @@
package shop;
/*
TODO Kassenbon System
*/
public class Order {
}

View File

@ -0,0 +1,81 @@
package shop;
/*
TODO
Setter getter tutorial schauen
*/
public class Product {
private int prodID;
private String name;
private double transportWeight;
private double netPrice;
private double mwst; // <----- Maybe final setzen
private int lagerbestand;
public Product(int prodID, String name, double transportWeight, double netPrice, double mwst, int lagerbestand) {
this.prodID = prodID;
this.name = name;
this.transportWeight = transportWeight;
this.netPrice = netPrice;
this.mwst = mwst;
this.lagerbestand = lagerbestand;
}
//Aus den Vorlesungen
@Override
public boolean equals(Object o) {
if (!(o instanceof Product))
return false;
if (!this.name.equals(((Product) o).name) || this.netPrice != ((Product) o).netPrice)
return false;
return true;
}
//Get ---> Methoden zum abrufen der Vals
public String getName() {
return name;
}
public int getLagerbestand() {
return lagerbestand;
}
public int getProdID() {
return prodID;
}
public double getNetPrice() {
return netPrice;
}
public double getMwst() {
return mwst;
}
public double getTransportWeight() {
return transportWeight;
}
public String toString() {
return "ID:" + prodID + " | " + name + " | " + netPrice + "€";
}
//mwst berechnung
public double mwstCalc() {
double Steuerbetrag = this.netPrice * (19 / 100);
return Math.round(Steuerbetrag * 100) / 100;
}
public void setLagerbestand(int neuerLagerbestand) {
this.lagerbestand = neuerLagerbestand;
}
}

View File

@ -1,4 +1,4 @@
package shoppackage;
package shop;
import java.util.Scanner;
@ -12,10 +12,31 @@ getName ect..
*/
public class ShopTUI {
static Scanner scanner = new Scanner(System.in);
private static OnlineShop onlineShop;
void main(){
OnlineShop shop = new OnlineShop();
System.out.println("Hello Shop!");
}
public static void menu(){
/*
TODO
Product angebot
Product suche
Cartbar
Exit
*/
}
}

View File

@ -0,0 +1,5 @@
package shop;
class CartTest {
}

View File

@ -0,0 +1,5 @@
package shop;
class OnlineShopTest {
}

View File

@ -0,0 +1,5 @@
package shop;
class OrderTest {
}

View File

@ -0,0 +1,18 @@
package shop;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class ProductsTest {
@Test
void testConstr(){
Product p1 = new Product(1, "Bier", 2.2, 2.90,19,2);
assertEquals(0.19, p1.mwstCalc());
}
}

View File

@ -0,0 +1,5 @@
package shop;
class ShopTUITest {
}

View File

@ -1,25 +0,0 @@
package shoppackage;
/*
Controller Klasse des Projektes.
TODO
Lager bestand für ein x beliebiges product bauen ----> Herr Hummels ansatz aus VL ausarbeiten
Cart übergeben
Order klasse integrieren
Logik ---> Product suchen & Kauf abschluss? <---- Oder doch in TUI?
*/
import java.util.ArrayList;
public class OnlineShop {
ArrayList<Product> lager;
//ArrayList
public OnlineShop() {
lager = new ArrayList<Product>();
lager.add(new Product(1, "Riesling 0.7 l",
1.1, 4.20, 19, 87));
}
}

View File

@ -1,4 +0,0 @@
package shoppackage;
public class Order {
}

View File

@ -1,60 +0,0 @@
package shoppackage;
/*
TODO
Setter getter tutorial schauen
*/
public class Product {
private int prodID;
private String name;
private double transportWeight;
private double netto;
private double mwst; // <----- Maybe final setzen
private int lagerbestand;
public Product(int prodID, String name, double transportWeight, double netto, double mwst, int lagerbestand) {
this.prodID = prodID;
this.name = name;
this.transportWeight = transportWeight;
this.netto = netto;
this.mwst = mwst;
this.lagerbestand = lagerbestand;
}
//Aus den Vorlesungen
public boolean equals(Object o) {
if (!(o instanceof Product))
return false;
if (!this.name.equals(((Product)o).name)|| this.netto != ((Product)o).netto)
return false;
return true;
}
//Get ---> Methoden zum abrufen der Vals
public String getName() {
return name;
}
public int getLagerbestand(){
return lagerbestand;
}
public int getProdID(){
return prodID;
}
public double getNetto() {
return netto;
}
public double getMwst() {
return mwst;
}
public double getTransportWeight(){
return transportWeight;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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