Class Customer

java.lang.Object
com.goldenleaf.shop.model.User
com.goldenleaf.shop.model.Customer

@Entity public class Customer extends User
Entity representing a customer (registered user) of the online shop.

Extends the base User class and adds customer-specific attributes: mobile phone, unique email, bonus points, a shopping cart and payment methods.

A customer can:

Since:
1.0
See Also:
  • Constructor Details

  • Method Details

    • getMobile

      public String getMobile()
      Returns the customer's mobile phone number.
      Returns:
      mobile phone number
    • setMobile

      public void setMobile(String mobile) throws IncorrectMobileException
      Sets a new mobile phone number.
      Parameters:
      mobile - new mobile number
      Throws:
      IncorrectMobileException - if the provided mobile number is invalid
    • getEmail

      public String getEmail()
      Returns the customer's email address.
      Returns:
      email address
    • setEmail

      public void setEmail(String email) throws IncorrectEmailException
      Sets a new email address.
      Parameters:
      email - new email address
      Throws:
      IncorrectEmailException - if the provided email is invalid
    • getBonusPoints

      public int getBonusPoints()
      Returns the current amount of bonus points.
      Returns:
      bonus points count
    • setBonusPoints

      public void setBonusPoints(int bonuses)
      Sets the exact amount of bonus points.

      Only positive values are accepted; otherwise the operation is ignored.

      Parameters:
      bonuses - new bonus points value (must be greater than 0)
    • addBonusPoints

      public void addBonusPoints(int bonuses)
      Adds the specified number of bonus points to the current balance.

      Only positive values are added.

      Parameters:
      bonuses - number of points to add (must be greater than 0)
    • getShoppingCart

      public ShoppingCart getShoppingCart()
      Returns the customer's shopping cart.
      Returns:
      associated ShoppingCart, may be null if not yet assigned
    • setShoppingCart

      public void setShoppingCart(ShoppingCart shoppingCart)
      Assigns a shopping cart to this customer and establishes bidirectional relationship.
      Parameters:
      shoppingCart - the shopping cart to set (can be null to detach)
    • getPayments

      public List<CreditCard> getPayments()
      Returns the list of payment cards linked to this customer.
      Returns:
      unmodifiable view of payment cards is not provided - direct list access
    • makeReview

      public void makeReview(Product product, String content, int rating) throws IncorrectRatingException, EmptyAuthorException, EmptyContentException, EmptyProductException
      Creates and adds a review for the specified product.
      Parameters:
      product - the product being reviewed (cannot be null)
      content - review text (cannot be blank)
      rating - rating from 1 to 5
      Throws:
      IncorrectRatingException - if rating is not in range 1-5
      EmptyAuthorException - if author (current customer) is invalid
      EmptyContentException - if review content is blank
      EmptyProductException - if product is null
      See Also:
    • addPayment

      public void addPayment(CreditCard card) throws NullCustomerException
      Adds a credit card to the customer's payment methods and sets the bidirectional link.
      Parameters:
      card - the credit card to add (cannot be null)
      Throws:
      NullCustomerException - if the card's customer side cannot be set
    • removePayment

      public void removePayment(CreditCard card) throws NullCustomerException
      Removes a credit card from the customer's payment methods and clears the bidirectional link.
      Parameters:
      card - the credit card to remove
      Throws:
      NullCustomerException - if the card's customer reference cannot be cleared