Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public class AddProductToCartCommand implements Command {
  2. private final CartService carService;
  3. private final ProductService productService;
  4. private Scanner sc = new Scanner(System.in);
  5.  
  6. public AddProductToCartCommand(Context context) {
  7. carService = context.getCartService();
  8. productService = context.getProductService();
  9. }
  10.  
  11. @Override
  12. public void execute() {
  13. System.out.println("Write product id");
  14. String id = UserManager.getIdFromUser(sc);
  15.  
  16. Product p = productService.getProductById(Integer.parseInt(id));
  17. if (p == null) {
  18. System.out.println("Sorry , but we haven't got product with this id");
  19. return;
  20. }
  21. carService.addProductToCart(p);
  22. System.out.println("Product " + p + " was added.");
  23.  
  24. }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement