Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. package com.telerikacademy.cosmetics.models.products;
  2.  
  3. import com.telerikacademy.cosmetics.models.common.GenderType;
  4. import com.telerikacademy.cosmetics.models.contracts.Toothpaste;
  5.  
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. public class ToothpasteImpl implements Toothpaste {
  10. public static final int MIN_NAME_LENGTH = 3;
  11. public static final int MAX_NAME_LENGTH = 10;
  12. public static final int MIN_BRAND_LENGTH = 2;
  13. public static final int MAX_BRAND_LENGTH = 10;
  14. // public ToothpasteImpl(String v1, String v2, double v3, GenderType women, List<String> v4) {
  15. // }
  16.  
  17. // Implements Toothpaste
  18. //It has name, brand, price, gender, ingredients
  19.  
  20. private String name;
  21. private String brand;
  22. private double price;
  23. private GenderType gender;
  24. private List<String> ingredients = new ArrayList<>();
  25.  
  26. public ToothpasteImpl(String name, String brand, double price, GenderType gender, List<String> ingrediants) {
  27. setName(name);
  28. setBrand(brand);
  29. setPrice(price);
  30. setGender(gender);
  31. setIngredients(ingrediants);
  32.  
  33.  
  34. }
  35.  
  36. public String getName() {
  37. return name;
  38. }
  39.  
  40. private void setName(String name) {
  41. //Minimum toothpaste name’s length is 3 symbols and maximum is 10 symbols.
  42. if (name.length() < MIN_NAME_LENGTH || name.length() > MAX_NAME_LENGTH) {
  43. throw new IllegalArgumentException();
  44. }
  45. this.name = name;
  46. }
  47.  
  48. public String getBrand() {
  49. return brand;
  50. }
  51.  
  52. private void setBrand(String brand) {
  53. //Minimum toothpaste brand name’s length is 2 symbols and maximum is 10 symbols.
  54. if (brand.length() < MIN_BRAND_LENGTH || brand.length() > MAX_BRAND_LENGTH) {
  55. throw new IllegalArgumentException();
  56. }
  57.  
  58. this.brand = brand;
  59. }
  60.  
  61. public double getPrice() {
  62. return price;
  63. }
  64.  
  65. private void setPrice(double price) {
  66. //Price cannot be negative.
  67. if (price < 0) {
  68. throw new IllegalArgumentException();
  69. }
  70. this.price = price;
  71. }
  72.  
  73. public GenderType getGender() {
  74. return gender;
  75. }
  76.  
  77. private void setGender(GenderType gender) {
  78. //Gender type can be "Men", "Women" or "Unisex".
  79. this.gender = gender;
  80. }
  81.  
  82. @Override
  83. public String print() {
  84. return String.format("#Category: %s\n" + "#%s\n" + " #Price: $%,.2f\n" + " #Gender: %s\n" + " #Ingredients: %s\n" + " ===\n", getName(), getBrand(), getPrice(), getGender(), getIngredients());
  85. }
  86.  
  87. public List<String> getIngredients() {
  88. return new ArrayList<String>(ingredients);
  89. }
  90.  
  91. private void setIngredients(List<String> ingredients) {
  92. if (ingredients == null) {
  93. throw new IllegalArgumentException();
  94. }
  95.  
  96. this.ingredients = new ArrayList<>(ingredients);
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement