Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Store {
- private Warehouse warehouse;
- private Scanner scanner;
- public Store(Warehouse warehouse, Scanner scanner) {
- this.warehouse = warehouse;
- this.scanner = scanner;
- }
- // the method that handles the customers visit to the store.
- public void shop(String customer) {
- ShoppingCart cart = new ShoppingCart();
- System.out.println("Welcome to the store " + customer);
- System.out.println("our selection:");
- for (String product : this.warehouse.products()) {
- System.out.println(product);
- }
- while (true) {
- System.out.print("What to put in the cart (press enter to go to the register): ");
- String product = scanner.nextLine();
- if (product.isEmpty()) {
- break;
- }
- if(warehouse.products().contains(product)){
- this.warehouse.take(product);
- cart.add(product, this.warehouse.price(product));
- }
- // Add code here that adds the product to the cart,
- // If there is any in the warehouse, and reduces the stock in the warehouse
- // Dont't touch any of the other code!
- }
- System.out.println("your shoppingcart contents:");
- cart.print();
- System.out.println("total: " + cart.price());
- }
- }
Add Comment
Please, Sign In to add comment