korobushk

Store class

Aug 3rd, 2020 (edited)
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Store {
  4.  
  5.     private Warehouse warehouse;
  6.     private Scanner scanner;
  7.  
  8.     public Store(Warehouse warehouse, Scanner scanner) {
  9.         this.warehouse = warehouse;
  10.         this.scanner = scanner;
  11.     }
  12.  
  13.     // the method that handles the customers visit to the store.
  14.     public void shop(String customer) {
  15.         ShoppingCart cart = new ShoppingCart();
  16.         System.out.println("Welcome to the store " + customer);
  17.         System.out.println("our selection:");
  18.  
  19.         for (String product : this.warehouse.products()) {
  20.             System.out.println(product);
  21.         }
  22.  
  23.         while (true) {
  24.             System.out.print("What to put in the cart (press enter to go to the register): ");
  25.             String product = scanner.nextLine();
  26.             if (product.isEmpty()) {
  27.                 break;
  28.             }
  29.            if(warehouse.products().contains(product)){
  30.                this.warehouse.take(product);
  31.                cart.add(product, this.warehouse.price(product));
  32.            }
  33. // Add code here that adds the product to the cart,
  34.             // If there is any in the warehouse, and reduces the stock in the warehouse
  35.             // Dont't touch any of the other code!
  36.         }
  37.  
  38.         System.out.println("your shoppingcart contents:");
  39.         cart.print();
  40.         System.out.println("total: " + cart.price());
  41.     }
  42.  
  43. }
  44.  
Add Comment
Please, Sign In to add comment