#BIG Change + plus formated
CART: #FEAT - Mengenänderung in cart implementiert sowie Check Methoden für TUI ---> isEmpty: überprüft ob liste leer ist, getter Methode für cart -> getPositions: gibt positions zurück clear(): leert positions OnlineShop #FEAT - getter methode für Lagerbestand Order #FEAT - Attribute und Konstruktor implementiert ShopTUI #FEAT - Menu implementiert #FEAT - Show products implementiert ---> gibt Produkte aus #FEAT - run -implementiert --> gibt menu funktion #FEAT - exit implementiert ---> exit methode implementiert #FEAt - search implementiert ---> sucht produkt nach wort #FEAT - addToCart implementiert ---> Fügt produkt in cart hinzu #FEAT - showCart ---> halb implementiert, noch nicht fertig #FEAT - editCart implementiert ----> lässt bearbeiten von cart zu #FEAT - checkinOUT halb implementiert ---> checkt aus Product #refactored resources quellen.txt bearbeitet MP4 hinzugefügt into resources Notes entferntmain
parent
6f15feb5d3
commit
ff95a0b984
|
|
@ -1,25 +0,0 @@
|
|||
commiten-> wenn man zb eine methode gecodet hat und alles funktioniert einigermaßen -> commiten , mäßig als backup
|
||||
(man kanns auch erstmal lokal machen aber eig sinnvoll direkt pushen)
|
||||
-> Hummel will dass wir eigentlich direkt pushen, da es auch Teil der Aufgabe ist und er das
|
||||
anscheinend streng nimmt(anzahl der commits zw das man das
|
||||
zumindest wirklich pusht und nicht nur lokal lässt)
|
||||
|
||||
junit test wunsch->Musthave bei zb brutto ,gesamtwert des Warenkorbs,Mehrwertsteuerversand
|
||||
(das will er aufjedenfall haben, der rest muss nicht
|
||||
so ausführlich getestet werden)
|
||||
|
||||
Lagerbestand-> soll runtergehen wenn ein Produkt in den Warenkorb gelegt wird
|
||||
(und falls es wieder aus dem Warenkorb genommen wird
|
||||
soll auch der Lagerbestand wieder angepasst werden.
|
||||
|
||||
Warenkorb extra Klasse WarenkorbPosition
|
||||
-> empfielt Hummel für den Lagerbestand
|
||||
|
||||
|
||||
Bestellung soll nur einen Warenkorb kennen(?) 1zu1 Verbingung siehe UML
|
||||
|
||||
blackbox test, white boxtest anschauen
|
||||
-> er läd bsp test für den Gesamtpreis hoch
|
||||
mindestmaß an test -> Warenkorb und Produkt
|
||||
er zeigt bei seinem Test wie man rundungsfehler schreibt-> assertEquals(5.69,....., 0,001)[er hat es weggemacht schau
|
||||
auf git sein bsp zu dem WarenkorbTest an, diese 0,0001 ist die erlaubte abweichung ]
|
||||
Binary file not shown.
|
|
@ -20,4 +20,27 @@ Baeldung - ConcurrentModificationException
|
|||
https://www.baeldung.com/java-concurrentmodificationexception
|
||||
|
||||
Build an Online Shopping Cart System Using OOP in Java - Nakul Mitra
|
||||
https://towardsdev.com/build-an-online-shopping-cart-system-using-oop-in-java-e8e5797f8664
|
||||
https://towardsdev.com/build-an-online-shopping-cart-system-using-oop-in-java-e8e5797f8664
|
||||
|
||||
|
||||
Java application grocery ordering logic with OOP
|
||||
https://stackoverflow.com/questions/63426789/java-application-grocery-ordering-logic-with-oop
|
||||
|
||||
Als vorlage für CartPos
|
||||
|
||||
|
||||
isEmpty() W3-Schools
|
||||
https://www.w3schools.com/java/ref_string_isempty.asp
|
||||
|
||||
KI
|
||||
Prompt:
|
||||
Ich stehe einwenig auf dem Schlauch, wie kann ich meine prodQuantity verändern sodass diese einen neuen wert bekommt?
|
||||
public void updateProductQuantity(int prodID,int quantity) {
|
||||
for (CartPosition pos : positions) {
|
||||
if (quantity <= 0) {
|
||||
removeProduct(prodID);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,23 @@ public void addProduct(Product prod, int quantity){
|
|||
positions.add(new CartPosition(prod, quantity));
|
||||
}
|
||||
}
|
||||
public void updateProductQuantity(int prodID,int quantity) {
|
||||
|
||||
if (quantity <= 0) {
|
||||
removeProduct(prodID);
|
||||
return;
|
||||
}
|
||||
//KI
|
||||
for(CartPosition pos : positions){
|
||||
if(pos.getProduct().getProdID() == prodID){
|
||||
pos.setQuantity(quantity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void removeProduct(int productID){
|
||||
CartPosition gettinYETTED = null; //Pointer ref
|
||||
for(CartPosition pos : positions){
|
||||
|
|
@ -55,8 +72,16 @@ public void removeProduct(int productID){
|
|||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Auto completion hat eingegriffen lol
|
||||
public boolean isEmpty(){
|
||||
return positions.isEmpty();
|
||||
}
|
||||
//Autocompl ist eig aus
|
||||
public List<CartPosition> getPositions() {
|
||||
return positions;
|
||||
}
|
||||
//wäre das autocomplete?
|
||||
public void clear(){
|
||||
positions.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,18 +28,22 @@ public class OnlineShop {
|
|||
for (int i = 1; i < lines.size(); i++){
|
||||
String line = lines.get(i);
|
||||
String[] partsOfList = line.split(",");
|
||||
int id = Integer.valueOf(partsOfList[0]);
|
||||
int id = Integer.parseInt(partsOfList[0]);
|
||||
String name = partsOfList[1];
|
||||
double weight = Double.valueOf(partsOfList[2]);
|
||||
double net = Double.valueOf(partsOfList[3]);
|
||||
double mwst = Double.valueOf(partsOfList[4]);
|
||||
int stock = Integer.valueOf(partsOfList[5]);
|
||||
double weight = Double.parseDouble(partsOfList[2]);
|
||||
double net = Double.parseDouble(partsOfList[3]);
|
||||
double mwst = Double.parseDouble(partsOfList[4]);
|
||||
int stock = Integer.parseInt(partsOfList[5]);
|
||||
Product prd = new Product(id,name,weight,net,mwst,stock);
|
||||
lager.add(prd);
|
||||
}
|
||||
}
|
||||
public ArrayList<Product> getLager(){
|
||||
return lager;
|
||||
}
|
||||
|
||||
public String[] produktListe() {
|
||||
//aus VL
|
||||
public String[] productList() {
|
||||
String[] produkt = new String[lager.size()];
|
||||
for (int i = 0; i < lager.size(); i++)
|
||||
produkt[i] = lager.get(i).toString();
|
||||
|
|
@ -48,7 +52,7 @@ public class OnlineShop {
|
|||
}
|
||||
|
||||
public Product getProdId(int prodID){
|
||||
for(int i = 0; i < lager.size(); ){
|
||||
for(int i = 0; i < lager.size(); i++){
|
||||
Product prod = lager.get(i);
|
||||
if(prod.getProdID() == prodID){
|
||||
return prod;
|
||||
|
|
@ -59,6 +63,7 @@ public class OnlineShop {
|
|||
public ArrayList<Product> seachByName(String searchText){
|
||||
ArrayList<Product> result = new ArrayList<>();
|
||||
for(Product prod : lager){
|
||||
|
||||
if(prod.getName().equalsIgnoreCase(searchText)){
|
||||
result.add(prod);
|
||||
}
|
||||
|
|
@ -74,7 +79,7 @@ public class OnlineShop {
|
|||
}
|
||||
|
||||
|
||||
|
||||
// aus Sud
|
||||
public static ArrayList<String> readFile(String path) throws FileNotFoundException {
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
Scanner sc = new Scanner(new File(path));
|
||||
|
|
@ -86,5 +91,10 @@ public class OnlineShop {
|
|||
sc.close();
|
||||
return lines;
|
||||
}
|
||||
public void initShop(String csvPath) throws FileNotFoundException {
|
||||
ArrayList<String> lines = readFile(csvPath);
|
||||
loadProductsAndParse(lines);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,4 +3,17 @@ package shop.backend;
|
|||
TODO Kassenbon System
|
||||
*/
|
||||
public class Order {
|
||||
|
||||
Cart cart;
|
||||
String customerName;
|
||||
String address;
|
||||
|
||||
public Order(Cart cart, String customerName, String address){
|
||||
this.cart = cart;
|
||||
this.customerName = customerName;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class Product {
|
|||
//
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[%d] %-25s | %6.2f € Netto | Lager: %d", prodID, name, netPrice, stock);
|
||||
return String.format("[%d] %-25s | %6.2f € Netprice | Stock: %2d", prodID, name, netPrice, stock);
|
||||
}
|
||||
|
||||
//mwst berechnung ----> gibt nru die Steuer zurück
|
||||
|
|
@ -81,4 +81,7 @@ public class Product {
|
|||
this.stock = neuerLagerbestand;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
package shop.frontend;
|
||||
|
||||
import shop.backend.Cart;
|
||||
import shop.backend.CartPosition;
|
||||
import shop.backend.OnlineShop;
|
||||
import shop.backend.Product;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
/*
|
||||
|
|
@ -13,32 +17,141 @@ 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
|
||||
*/
|
||||
|
||||
|
||||
|
||||
static Scanner scanner = new Scanner(System.in);
|
||||
private static OnlineShop onlineShop;
|
||||
private static Cart cart;
|
||||
|
||||
void main() throws FileNotFoundException {
|
||||
//KI
|
||||
IO.println("\n+--------------------------------------+\n| " +
|
||||
" WELCOME TO THE TH MANNHEIM |\n| ONLINE SHOP " +
|
||||
"|\n+--------------------------------------+");
|
||||
IO.println("| |");
|
||||
onlineShop = new OnlineShop();
|
||||
cart = new Cart();
|
||||
onlineShop.initShop("Shop/resources/produkte.csv");
|
||||
run(onlineShop);
|
||||
|
||||
}
|
||||
|
||||
public static void menu() {
|
||||
|
||||
IO.println("+--------------------------------------+");
|
||||
IO.println("|1. Show products |");
|
||||
IO.println("|2. Search |");
|
||||
IO.println("|3. Add to cart |");
|
||||
IO.println("|4. Show cart |");
|
||||
IO.println("|5. Edit cart |");
|
||||
IO.println("|6. Check out |");
|
||||
IO.println("|7. Exit |");
|
||||
IO.println("|Your choice: |");
|
||||
IO.println("+--------------------------------------+");
|
||||
}
|
||||
|
||||
}
|
||||
public static void showProducts() {
|
||||
IO.println();
|
||||
IO.println("Product showcase");
|
||||
for (Product prod : onlineShop.getLager()) {
|
||||
IO.println(prod);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void run(OnlineShop shop) {
|
||||
int choice;
|
||||
do {
|
||||
menu();
|
||||
|
||||
choice = scanner.nextInt();
|
||||
switch (choice) {
|
||||
case 1:
|
||||
showProducts();
|
||||
break;
|
||||
case 2:
|
||||
search();
|
||||
break;
|
||||
case 3:
|
||||
addToCart();
|
||||
break;
|
||||
case 4:
|
||||
showCart();
|
||||
break;
|
||||
case 5:
|
||||
editCart();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
checkinOut();
|
||||
break;
|
||||
case 7:
|
||||
exit();
|
||||
break;
|
||||
}
|
||||
} while (choice != 7);
|
||||
|
||||
}
|
||||
|
||||
public static void exit() {
|
||||
IO.println("Thank you for visiting.....");
|
||||
}
|
||||
|
||||
public static void search() {
|
||||
String keyWord = IO.readln("Keyword ur lookin for: ");
|
||||
for (Product pr : onlineShop.seachByName(keyWord)) {
|
||||
IO.println(pr);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void addToCart() {
|
||||
String strId = IO.readln("Prod ID ur lookin for: ");
|
||||
int id = Integer.parseInt(strId);
|
||||
Product p = onlineShop.getProdId(id);
|
||||
if (p == null) { //Pointer auf leere referenz
|
||||
IO.println("Product not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
String strQuantity = IO.readln("Enter quantity: ");
|
||||
int quantity = Integer.parseInt(strQuantity);
|
||||
if (quantity > p.getStock()) {
|
||||
IO.println("Not enough in stock, sorry!");
|
||||
IO.println("Available: " + p.getStock());
|
||||
} else {
|
||||
cart.addProduct(p, quantity);
|
||||
IO.println("Added to cart: ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void showCart() {
|
||||
if (!cart.isEmpty()) {
|
||||
for (CartPosition pos : cart.getPositions()) {
|
||||
IO.println(pos);
|
||||
}
|
||||
IO.println("Summe ist: (NotImplemented yet....)"); //TODO CartBerechnungen
|
||||
}
|
||||
IO.println("Cart is empty.");
|
||||
}
|
||||
|
||||
public static void editCart() {
|
||||
showCart();
|
||||
if (cart.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String strId = IO.readln("ID to change: ");
|
||||
int id = Integer.parseInt(strId);
|
||||
String strQuantity = IO.readln("Quantity you want to change: ");
|
||||
int quantity = Integer.parseInt(strQuantity);
|
||||
cart.updateProductQuantity(id, quantity);
|
||||
IO.println("Cart has changed!");
|
||||
|
||||
}
|
||||
|
||||
public static void checkinOut() {
|
||||
if (cart.isEmpty()) {
|
||||
IO.println("Cart empty, you can't order yet!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue