Add name/address input to checkout
parent
a987746e01
commit
72e7a101b8
|
|
@ -4,7 +4,6 @@ import java.io.File;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
|
|
@ -14,7 +13,8 @@ public class Main {
|
|||
TUI tui = new TUI(shop);
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
while (true) {
|
||||
System.out.print("> ");
|
||||
if (!tui.isCheckingOut())
|
||||
System.out.print("> ");
|
||||
String input = scanner.nextLine();
|
||||
tui.processInput(input);
|
||||
if (tui.exit) {
|
||||
|
|
|
|||
|
|
@ -9,17 +9,24 @@ public class TUI {
|
|||
|
||||
Shop shop;
|
||||
boolean exit = false;
|
||||
int checkoutStep = 0;
|
||||
String checkoutName = null;
|
||||
String checkoutAddress = null;
|
||||
|
||||
public TUI(Shop shop) {
|
||||
this.shop = shop;
|
||||
}
|
||||
|
||||
public void processInput(String input) {
|
||||
if (isCheckingOut()) {
|
||||
checkout(input);
|
||||
return;
|
||||
}
|
||||
String[] tokens = input.split("\\s+");
|
||||
String command = tokens[0];
|
||||
switch (command) {
|
||||
case "exit" -> exit();
|
||||
case "checkout" -> checkout();
|
||||
case "checkout" -> checkout(null);
|
||||
case "list" -> listProducts(shop.products);
|
||||
case "cart" -> listCart(shop.getCart());
|
||||
case "add" -> shop.addProductToCart(shop.getProductById(Integer.parseInt(tokens[1])));
|
||||
|
|
@ -46,11 +53,36 @@ public class TUI {
|
|||
});
|
||||
}
|
||||
|
||||
public void checkout() {
|
||||
Order order = shop.checkout();
|
||||
System.out.println("MwSt.: " + order.calculateTotalVat() + "€");
|
||||
System.out.println("Versand: " + order.calculateShippingCost() + "€");
|
||||
System.out.println("Brutto: " + order.calculateTotalPriceWithVat() + "€");
|
||||
public void checkout(String input) {
|
||||
switch (checkoutStep) {
|
||||
case 0 -> {
|
||||
System.out.println();
|
||||
System.out.println("Bestellung abschließen");
|
||||
System.out.print("Name: ");
|
||||
checkoutStep = 1;
|
||||
}
|
||||
case 1 -> {
|
||||
checkoutName = input;
|
||||
System.out.print("Adresse: ");
|
||||
checkoutStep = 2;
|
||||
}
|
||||
case 2 -> {
|
||||
checkoutAddress = input;
|
||||
Order order = shop.checkout();
|
||||
System.out.println("Vielen Dank für Ihre Bestellung, " + checkoutName + "!");
|
||||
System.out.println("Ihre Bestellung wird an folgende Adresse gesendet: " + checkoutAddress);
|
||||
System.out.println("---");
|
||||
System.out.println("MwSt.: " + order.calculateTotalVat() + "€");
|
||||
System.out.println("Versand: " + order.calculateShippingCost() + "€");
|
||||
System.out.println("Brutto: " + order.calculateTotalPriceWithVat() + "€");
|
||||
System.out.println("---");
|
||||
checkoutStep = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCheckingOut() {
|
||||
return checkoutStep > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue