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 sun.reflect.generics.reflectiveObjects.NotImplementedException;
- public class Product {
- private double price;
- private String name;
- private String brand;
- private GenderType gender;
- private static final int MIN_NAME_LENGTH = 3;
- private static final int MAX_NAME_LENGTH = 10;
- private static final int MIN_BRAND_LENGTH = 2;
- private static final int MAX_BRAND_LENGTH = 10;
- public double getPrice() {
- return price;
- }
- public void setPrice(double price) {
- this.price = price;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getBrand() {
- return brand;
- }
- public void setBrand(String brand) {
- this.brand = brand;
- }
- public GenderType getGender() {
- return gender;
- }
- public void setGender(GenderType gender) {
- this.gender = gender;
- }
- public Product(String name, String brand, double price, GenderType gender) {
- if(name.length()<MIN_NAME_LENGTH || name.length()>MAX_NAME_LENGTH){
- throw new IllegalArgumentException("Product name should be between 3 and 10 symbols");
- }
- if(brand.length()<MIN_BRAND_LENGTH|| brand.length()>MAX_BRAND_LENGTH){
- throw new IllegalArgumentException("Brand name should be between 2 and 10 symbols");
- }
- if(price<0){
- throw new IllegalArgumentException("Enter valid price");
- }
- //throw new NotImplementedException();
- }
- public String print() {
- return String.format(" #",name,brand," #Price:",price,"#Gender:",gender,"===");
- //Format:
- //" #[Name] [Brand]
- // #Price: [Price]
- // #Gender: [Gender]
- // ==="
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment