This is the code that I have been working on, and it is really a huge problem, I cant use any statement only those you see here, I need help :D thank you
if (choice == 1) {
buyer.listProducts(seller);
int productId, quantity;
boolean validInput = false;
while (!validInput) {
System.out.print("Enter the ID of the product to add to the cart: ");
if (scanner.hasNextInt()) {
productId = scanner.nextInt();
Product productToAdd = findProductById(productId, seller);
if (productToAdd != null) {
validInput = true;
// Prompt for the quantity
validQuantity = false;
while (!validQuantity) {
System.out.print("Enter quantity: ");
if (scanner.hasNextInt()) {
quantity = scanner.nextInt();
if (quantity > 0 && quantity <= productToAdd.quantity) {
validQuantity = true;
} else {
System.out.println("Invalid quantity or not enough stock.");
}
} else {
System.out.println("Invalid input. Please enter a valid quantity (a positive integer).");
scanner.next(); // Clear the input buffer
}
}
if (validQuantity) {
buyer.addToCart(productToAdd, quantity);
System.out.println("Product added to cart!");
}
} else {
System.out.println("Product not found. Please enter a valid product ID.");
}
} else {
System.out.println("Invalid input. Please enter a valid product ID (a number).");
scanner.next(); // Clear the input buffer
}
}
}
This is the code that I was working on and I am still confuse on what I am gonna do, I need help from you guys
I wanted to make the "Product added to cart!" only show once