aneliyanestorova

Product

Jun 13th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. package com.telerikacademy.cosmetics.models.products;
  2.  
  3. import com.telerikacademy.cosmetics.models.common.GenderType;
  4. import sun.reflect.generics.reflectiveObjects.NotImplementedException;
  5.  
  6. public class Product {
  7.  
  8. private double price;
  9. private String name;
  10. private String brand;
  11. private GenderType gender;
  12. private static final int MIN_NAME_LENGTH = 3;
  13. private static final int MAX_NAME_LENGTH = 10;
  14. private static final int MIN_BRAND_LENGTH = 2;
  15. private static final int MAX_BRAND_LENGTH = 10;
  16.  
  17.  
  18. public double getPrice() {
  19. return price;
  20. }
  21.  
  22. public void setPrice(double price) {
  23. this.price = price;
  24. }
  25.  
  26. public String getName() {
  27. return name;
  28. }
  29.  
  30. public void setName(String name) {
  31. this.name = name;
  32. }
  33.  
  34. public String getBrand() {
  35. return brand;
  36. }
  37.  
  38. public void setBrand(String brand) {
  39. this.brand = brand;
  40. }
  41.  
  42. public GenderType getGender() {
  43. return gender;
  44. }
  45.  
  46. public void setGender(GenderType gender) {
  47. this.gender = gender;
  48. }
  49.  
  50. public Product(String name, String brand, double price, GenderType gender) {
  51.  
  52. if(name.length()<MIN_NAME_LENGTH || name.length()>MAX_NAME_LENGTH){
  53. throw new IllegalArgumentException("Product name should be between 3 and 10 symbols");
  54. }
  55. if(brand.length()<MIN_BRAND_LENGTH|| brand.length()>MAX_BRAND_LENGTH){
  56. throw new IllegalArgumentException("Brand name should be between 2 and 10 symbols");
  57. }
  58. if(price<0){
  59. throw new IllegalArgumentException("Enter valid price");
  60. }
  61. //throw new NotImplementedException();
  62.  
  63. }
  64.  
  65.  
  66. public String print() {
  67.  
  68. return String.format(" #",name,brand," #Price:",price,"#Gender:",gender,"===");
  69.  
  70.  
  71. //Format:
  72. //" #[Name] [Brand]
  73. // #Price: [Price]
  74. // #Gender: [Gender]
  75. // ==="
  76.  
  77. }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment