#Refactored
Order erweitert aus cart rechnungen entfernt. Trchnungen waren aus KI prompt ü 7 Zeilen <--- musste also entfernen TUI angepasstmain
parent
aa059450e1
commit
61252aae03
|
|
@ -64,14 +64,7 @@ public void removeProduct(int productID){
|
||||||
positions.remove(gettinYETTED);
|
positions.remove(gettinYETTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Price of all pos without them taxes :p
|
|
||||||
public double getTotalPrice() {
|
|
||||||
double sum = 0;
|
|
||||||
for(CartPosition pos : positions){
|
|
||||||
sum += pos.getTotalPrice();
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
//Auto completion hat eingegriffen lol
|
//Auto completion hat eingegriffen lol
|
||||||
public boolean isEmpty(){
|
public boolean isEmpty(){
|
||||||
return positions.isEmpty();
|
return positions.isEmpty();
|
||||||
|
|
@ -84,77 +77,8 @@ public void removeProduct(int productID){
|
||||||
public void clear(){
|
public void clear(){
|
||||||
positions.clear();
|
positions.clear();
|
||||||
}
|
}
|
||||||
//Brutto aller pos mit mwst
|
|
||||||
public double getThemBruttoPrices() {
|
|
||||||
double sum = 0;
|
|
||||||
for (CartPosition pos : positions) {
|
|
||||||
sum += pos.getTotalPrice();
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
public double getWeight(){
|
|
||||||
double weight = 0;
|
|
||||||
for(CartPosition pos : positions){
|
|
||||||
weight += pos.getProductWeight();
|
|
||||||
}
|
|
||||||
return weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getShippingCost(){
|
|
||||||
double value = getThemBruttoPrices();
|
|
||||||
if(value >= 500) return 0.0;
|
|
||||||
double weight = getWeight();
|
|
||||||
if(weight <= 0.1) return 3.95;
|
|
||||||
if(weight <= 1.0) return 4.95;
|
|
||||||
if(weight <= 5.0) return 5.95;
|
|
||||||
return 19.95;
|
|
||||||
}
|
|
||||||
public double getMwstRateOf7(){
|
|
||||||
double sum = 0;
|
|
||||||
for(CartPosition pos : positions){
|
|
||||||
if(pos.getMwstRate() == 7);
|
|
||||||
sum += pos.getMwstAmount();
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
public double getMwstRateOf19(){
|
|
||||||
double sum = 0;
|
|
||||||
for(CartPosition pos : positions){
|
|
||||||
if(pos.getMwstRate() == 19);
|
|
||||||
sum += pos.getMwstAmount();
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Formel und prinzip nach KI-Prompt
|
|
||||||
public double getFinalTotal(){
|
|
||||||
double total7 = 0;
|
|
||||||
double total19 = 0;
|
|
||||||
for(CartPosition pos : positions){
|
|
||||||
if(pos.getMwstRate() == 7){
|
|
||||||
total7 += pos.getTotalBruttoPrice();
|
|
||||||
|
|
||||||
}else {
|
|
||||||
total19 += pos.getTotalBruttoPrice();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
double totalBrutto = total7 + total19;
|
|
||||||
double shipbrutto = getShippingCost();
|
|
||||||
if(shipbrutto > 0){
|
|
||||||
if(totalBrutto > 0){
|
|
||||||
//Verhältnis und wenn Waren mit unterschiedlichen mwst im warenkorb sind
|
|
||||||
double ratio7 = total7 / totalBrutto;
|
|
||||||
double ratio19 = total19 / totalBrutto;
|
|
||||||
|
|
||||||
double shippingBy7 = totalBrutto * ratio7;
|
|
||||||
double shippingBy19 = totalBrutto * ratio19;
|
|
||||||
// Hier wird nur der Gesamtbetrag berechnet, nicht die MwSt-Aufteilung
|
|
||||||
// Die anteiligen Versandkosten werden einfach addiert
|
|
||||||
return totalBrutto + shippingBy7 + shippingBy19;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return totalBrutto;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,95 @@
|
||||||
package shop.backend;
|
package shop.backend;
|
||||||
/*
|
|
||||||
TODO Kassenbon System
|
import shop.backend.CartPosition;
|
||||||
*/
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Order {
|
public class Order {
|
||||||
|
private String customerName;
|
||||||
|
private String address;
|
||||||
|
private List<CartPosition> positions;
|
||||||
|
private double totalNet;
|
||||||
|
private double totalBrutto;
|
||||||
|
private double shippingCost;
|
||||||
|
private double finalTotal;
|
||||||
|
|
||||||
Cart cart;
|
|
||||||
String customerName;
|
|
||||||
String address;
|
|
||||||
|
|
||||||
public Order(Cart cart, String customerName, String address){
|
public Order(String customerName, String address, List<CartPosition> positions) {
|
||||||
this.cart = cart;
|
|
||||||
this.customerName = customerName;
|
this.customerName = customerName;
|
||||||
this.address = address;
|
this.address = address;
|
||||||
|
this.positions = new ArrayList<>();
|
||||||
|
|
||||||
|
//KI Bug fix
|
||||||
|
for (CartPosition pos : positions) {
|
||||||
|
this.positions.add(new CartPosition(pos.getProduct(), pos.getQuantity()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void calculateShippingCost() {
|
||||||
|
//wenn ü 500 dann ist free
|
||||||
|
if (totalBrutto >= 500) {
|
||||||
|
shippingCost = 0.0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
double weight = 0;
|
||||||
|
for (CartPosition pos : positions) {
|
||||||
|
weight += pos.getProductWeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
//KI Ansatz
|
||||||
|
if (weight <= 0.1) {
|
||||||
|
shippingCost = 3.95;
|
||||||
|
} else if (weight <= 1.0) {
|
||||||
|
shippingCost = 4.95;
|
||||||
|
} else if (weight <= 5.0) {
|
||||||
|
shippingCost = 5.95;
|
||||||
|
} else {
|
||||||
|
shippingCost = 19.95;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printConfirmation() {
|
||||||
|
IO.println("----------------------------------------");
|
||||||
|
IO.println(" ORDER CONFIRMATION ");
|
||||||
|
IO.println("----------------------------------------");
|
||||||
|
IO.println("Customer: " + customerName);
|
||||||
|
IO.println("Delivery address: " + address);
|
||||||
|
IO.println("----------------------------------------");
|
||||||
|
IO.println("Your order:");
|
||||||
|
|
||||||
|
for (CartPosition pos : positions) {
|
||||||
|
IO.println(" " + pos.getProduct().getName() + " x " + pos.getQuantity());
|
||||||
|
}
|
||||||
|
|
||||||
|
IO.println("----------------------------------------");
|
||||||
|
IO.println(String.format("Product value: %6.2f €", totalNet));
|
||||||
|
IO.println("----------------------------------------");
|
||||||
|
IO.println("Thank you for your order, lil bro!");
|
||||||
|
IO.println("----------------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getCustomerName() {
|
||||||
|
return customerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CartPosition> getPositions() {
|
||||||
|
return positions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getTotalNet() {
|
||||||
|
return totalNet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getFinalTotal() {
|
||||||
|
return finalTotal;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ public class Product {
|
||||||
private String name;
|
private String name;
|
||||||
private double transportWeight;
|
private double transportWeight;
|
||||||
private double netPrice;
|
private double netPrice;
|
||||||
private double bruttoPrice;
|
|
||||||
private double mwst; // <----- Maybe final setzen
|
private double mwst; // <----- Maybe final setzen
|
||||||
private int stock;
|
private int stock;
|
||||||
|
|
||||||
|
|
@ -54,8 +54,9 @@ public class Product {
|
||||||
public double getNetPrice() {
|
public double getNetPrice() {
|
||||||
return netPrice;
|
return netPrice;
|
||||||
}
|
}
|
||||||
|
//Änderung aus ansatz azs vl
|
||||||
public double getBruttoPrice() {
|
public double getBruttoPrice() {
|
||||||
return bruttoPrice;
|
return Math.round(netPrice * (1 + mwst/100));
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMwst() {
|
public double getMwst() {
|
||||||
|
|
@ -71,15 +72,6 @@ public class Product {
|
||||||
return String.format("[%d] %-25s | %6.2f € Netprice | Stock: %2d", 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
|
|
||||||
public double mwstCalc() {
|
|
||||||
return Math.round(netPrice * (mwst / 100));
|
|
||||||
}
|
|
||||||
//Gibt preis versteuert zurück
|
|
||||||
public double mwstOnPrice(){
|
|
||||||
return Math.round(netPrice * (mwst / 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Lagerbestand kann sich ändern. Einzige setter Methode
|
//Lagerbestand kann sich ändern. Einzige setter Methode
|
||||||
public void setStock(int neuerLagerbestand) {
|
public void setStock(int neuerLagerbestand) {
|
||||||
this.stock = neuerLagerbestand;
|
this.stock = neuerLagerbestand;
|
||||||
|
|
|
||||||
|
|
@ -3,66 +3,53 @@ package shop.frontend;
|
||||||
import shop.backend.Cart;
|
import shop.backend.Cart;
|
||||||
import shop.backend.CartPosition;
|
import shop.backend.CartPosition;
|
||||||
import shop.backend.OnlineShop;
|
import shop.backend.OnlineShop;
|
||||||
|
import shop.backend.Order;
|
||||||
import shop.backend.Product;
|
import shop.backend.Product;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.Scanner;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/*
|
|
||||||
IO Only und Darstellungslogik (Nur Anzeigen, bekommen, nichts verändern)
|
|
||||||
keine Business logik <----- Ein einziger Scanner für TUI
|
|
||||||
ruft Methoden aus Onlineshop auf oder auch CartPos und product <---Ungewiss
|
|
||||||
getName ect..
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
public class ShopTUI {
|
public class ShopTUI {
|
||||||
static Scanner scanner = new Scanner(System.in);
|
|
||||||
private static OnlineShop onlineShop;
|
private static OnlineShop onlineShop;
|
||||||
private static Cart cart;
|
private static Cart cart;
|
||||||
|
|
||||||
void main() throws FileNotFoundException {
|
public static void main(String[] args) throws FileNotFoundException {
|
||||||
//KI
|
IO.println("\n+--------------------------------------+");
|
||||||
IO.println("\n+--------------------------------------+\n| " +
|
IO.println("| WELCOME TO THE ONLINE SHOP |");
|
||||||
" WELCOME TO THE TH MANNHEIM |\n| ONLINE SHOP " +
|
IO.println("+--------------------------------------+");
|
||||||
"|\n+--------------------------------------+");
|
|
||||||
IO.println("| |");
|
|
||||||
onlineShop = new OnlineShop();
|
onlineShop = new OnlineShop();
|
||||||
cart = new Cart();
|
cart = new Cart();
|
||||||
onlineShop.initShop("Shop/resources/produkte.csv");
|
onlineShop.initShop("Shop/resources/produkte.csv");
|
||||||
run(onlineShop);
|
run();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void menu() {
|
public static void menu() {
|
||||||
|
IO.println("\n+--------------------------------------+");
|
||||||
IO.println("+--------------------------------------+");
|
IO.println("|1. Show all products |");
|
||||||
IO.println("|1. Show products |");
|
IO.println("|2. Search products |");
|
||||||
IO.println("|2. Search |");
|
|
||||||
IO.println("|3. Add to cart |");
|
IO.println("|3. Add to cart |");
|
||||||
IO.println("|4. Show cart |");
|
IO.println("|4. Show cart |");
|
||||||
IO.println("|5. Edit cart |");
|
IO.println("|5. Edit cart |");
|
||||||
IO.println("|6. Check out |");
|
IO.println("|6. Checkout |");
|
||||||
IO.println("|7. Exit |");
|
IO.println("|7. Exit |");
|
||||||
IO.println("|Your choice: |");
|
|
||||||
IO.println("+--------------------------------------+");
|
IO.println("+--------------------------------------+");
|
||||||
|
IO.print("Your choice: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showProducts() {
|
public static void showProducts() {
|
||||||
IO.println();
|
IO.println("\nProduct overview:");
|
||||||
IO.println("Product showcase");
|
|
||||||
for (Product prod : onlineShop.getLager()) {
|
for (Product prod : onlineShop.getLager()) {
|
||||||
IO.println(prod);
|
IO.println(prod);
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void run(OnlineShop shop) {
|
}
|
||||||
|
|
||||||
|
public static void run() {
|
||||||
int choice;
|
int choice;
|
||||||
do {
|
do {
|
||||||
menu();
|
menu();
|
||||||
|
choice = Integer.parseInt(IO.readln());
|
||||||
choice = scanner.nextInt();
|
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 1:
|
case 1:
|
||||||
showProducts();
|
showProducts();
|
||||||
|
|
@ -79,79 +66,132 @@ public class ShopTUI {
|
||||||
case 5:
|
case 5:
|
||||||
editCart();
|
editCart();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
checkinOut();
|
checkout();
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
exit();
|
exit();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
} while (choice != 7);
|
} while (choice != 7);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void exit() {
|
public static void exit() {
|
||||||
IO.println("Thank you for visiting.....");
|
IO.println("Thank you for your visit!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void search() {
|
public static void search() {
|
||||||
String keyWord = IO.readln("Keyword ur lookin for: ");
|
String keyWord = IO.readln("Search term: ");
|
||||||
for (Product pr : onlineShop.seachByName(keyWord)) {
|
ArrayList<Product> results = onlineShop.seachByName(keyWord);
|
||||||
IO.println(pr);
|
|
||||||
|
|
||||||
|
if (results.isEmpty()) {
|
||||||
|
IO.println("No products found!");
|
||||||
|
} else {
|
||||||
|
IO.println("\nSearch results:");
|
||||||
|
|
||||||
|
for (Product pr : results) {
|
||||||
|
IO.println(pr);
|
||||||
|
}
|
||||||
|
IO.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addToCart() {
|
public static void addToCart() {
|
||||||
String strId = IO.readln("Prod ID ur lookin for: ");
|
String strId = IO.readln("Product ID: ");
|
||||||
int id = Integer.parseInt(strId);
|
int id = Integer.parseInt(strId);
|
||||||
Product p = onlineShop.getProdId(id);
|
Product p = onlineShop.getProdId(id);
|
||||||
if (p == null) { //Pointer auf leere referenz
|
|
||||||
|
if (p == null) {
|
||||||
IO.println("Product not found!");
|
IO.println("Product not found!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String strQuantity = IO.readln("Enter quantity: ");
|
String strQuantity = IO.readln("Quantity: ");
|
||||||
int quantity = Integer.parseInt(strQuantity);
|
int quantity = Integer.parseInt(strQuantity);
|
||||||
|
|
||||||
if (quantity > p.getStock()) {
|
if (quantity > p.getStock()) {
|
||||||
IO.println("Not enough in stock, sorry!");
|
IO.println("Not enough in stock!");
|
||||||
IO.println("Available: " + p.getStock());
|
IO.println("Available: " + p.getStock());
|
||||||
} else {
|
} else {
|
||||||
cart.addProduct(p, quantity);
|
cart.addProduct(p, quantity);
|
||||||
IO.println("Added to cart: ");
|
IO.println("Added: " + p.getName() + " x " + quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showCart() {
|
public static void showCart() {
|
||||||
if (!cart.isEmpty()) {
|
if (cart.isEmpty()) {
|
||||||
|
IO.println("Cart is empty.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Order tempOrder = new Order("", "", cart.getPositions());
|
||||||
|
|
||||||
|
IO.println("\nYour shopping cart:");
|
||||||
|
IO.println("----------------------------------------");
|
||||||
for (CartPosition pos : cart.getPositions()) {
|
for (CartPosition pos : cart.getPositions()) {
|
||||||
IO.println(pos);
|
IO.println(pos);
|
||||||
}
|
}
|
||||||
IO.println("Summe ist: (NotImplemented yet....)"); //TODO CartBerechnungen
|
IO.println("----------------------------------------");
|
||||||
}
|
IO.println(String.format("Product value (net): %6.2f €", tempOrder.getTotalNet()));
|
||||||
IO.println("Cart is empty.");
|
IO.println(String.format("TOTAL: %6.2f €", tempOrder.getFinalTotal()));
|
||||||
|
IO.println("----------------------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void editCart() {
|
public static void editCart() {
|
||||||
showCart();
|
|
||||||
if (cart.isEmpty()) {
|
if (cart.isEmpty()) {
|
||||||
|
IO.println("Cart is empty!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String strId = IO.readln("ID to change: ");
|
|
||||||
|
showCart();
|
||||||
|
String strId = IO.readln("Product ID to change: ");
|
||||||
int id = Integer.parseInt(strId);
|
int id = Integer.parseInt(strId);
|
||||||
String strQuantity = IO.readln("Quantity you want to change: ");
|
for (CartPosition pos : cart.getPositions()) {
|
||||||
|
if (pos.getProduct().getProdID() == id) {
|
||||||
|
String strQuantity = IO.readln("New quantity (0 to remove): ");
|
||||||
int quantity = Integer.parseInt(strQuantity);
|
int quantity = Integer.parseInt(strQuantity);
|
||||||
cart.updateProductQuantity(id, quantity);
|
cart.updateProductQuantity(id, quantity);
|
||||||
IO.println("Cart has changed!");
|
IO.println("Cart updated!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkinOut() {
|
public static void checkout() {
|
||||||
if (cart.isEmpty()) {
|
if (cart.isEmpty()) {
|
||||||
IO.println("Cart empty, you can't order yet!");
|
IO.println("Cart is empty!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
IO.println("\n--- CHECKOUT ---");
|
||||||
|
String name = IO.readln("Name: ");
|
||||||
|
String address = IO.readln("Delivery address: ");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (CartPosition pos : cart.getPositions()) {
|
||||||
|
Product prod = pos.getProduct();
|
||||||
|
int quantity = pos.getQuantity();
|
||||||
|
|
||||||
|
if (prod.getStock() < quantity) {
|
||||||
|
IO.println("Error: " + prod.getName() + " not enough in stock!");
|
||||||
|
IO.println("Available: " + prod.getStock() + ", Requested: " + quantity);
|
||||||
|
IO.println("Order cannot be completed!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (CartPosition pos : cart.getPositions()) {
|
||||||
|
Product prod = pos.getProduct();
|
||||||
|
int quantity = pos.getQuantity();
|
||||||
|
onlineShop.reduceStock(prod, quantity);
|
||||||
|
}
|
||||||
|
|
||||||
|
Order order = new Order(name, address, cart.getPositions());
|
||||||
|
order.printConfirmation();
|
||||||
|
|
||||||
|
cart.clear();
|
||||||
|
IO.println("Cart has been cleared. You can continue shopping!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue