Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.telerikacademy.cosmetics.models.products;
- import com.telerikacademy.cosmetics.models.common.GenderType;
- import com.telerikacademy.cosmetics.models.contracts.Toothpaste;
- import java.util.ArrayList;
- import java.util.List;
- public class ToothpasteImpl implements Toothpaste {
- public static final int MIN_NAME_LENGTH = 3;
- public static final int MAX_NAME_LENGTH = 10;
- public static final int MIN_BRAND_LENGTH = 2;
- public static final int MAX_BRAND_LENGTH = 10;
- // public ToothpasteImpl(String v1, String v2, double v3, GenderType women, List<String> v4) {
- // }
- // Implements Toothpaste
- //It has name, brand, price, gender, ingredients
- private String name;
- private String brand;
- private double price;
- private GenderType gender;
- private List<String> ingredients = new ArrayList<>();
- public ToothpasteImpl(String name, String brand, double price, GenderType gender, List<String> ingrediants) {
- setName(name);
- setBrand(brand);
- setPrice(price);
- setGender(gender);
- setIngredients(ingrediants);
- }
- public String getName() {
- return name;
- }
- private void setName(String name) {
- //Minimum toothpaste name’s length is 3 symbols and maximum is 10 symbols.
- if (name.length() < MIN_NAME_LENGTH || name.length() > MAX_NAME_LENGTH) {
- throw new IllegalArgumentException();
- }
- this.name = name;
- }
- public String getBrand() {
- return brand;
- }
- private void setBrand(String brand) {
- //Minimum toothpaste brand name’s length is 2 symbols and maximum is 10 symbols.
- if (brand.length() < MIN_BRAND_LENGTH || brand.length() > MAX_BRAND_LENGTH) {
- throw new IllegalArgumentException();
- }
- this.brand = brand;
- }
- public double getPrice() {
- return price;
- }
- private void setPrice(double price) {
- //Price cannot be negative.
- if (price < 0) {
- throw new IllegalArgumentException();
- }
- this.price = price;
- }
- public GenderType getGender() {
- return gender;
- }
- private void setGender(GenderType gender) {
- //Gender type can be "Men", "Women" or "Unisex".
- this.gender = gender;
- }
- @Override
- public String print() {
- return String.format("#Category: %s\n" + "#%s\n" + " #Price: $%,.2f\n" + " #Gender: %s\n" + " #Ingredients: %s\n" + " ===\n", getName(), getBrand(), getPrice(), getGender(), getIngredients());
- }
- public List<String> getIngredients() {
- return new ArrayList<String>(ingredients);
- }
- private void setIngredients(List<String> ingredients) {
- if (ingredients == null) {
- throw new IllegalArgumentException();
- }
- this.ingredients = new ArrayList<>(ingredients);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement