|
| 1 | +/* |
| 2 | + * Copyright (C) 2021 fullarray |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | +package labs.pm.data; |
| 18 | + |
| 19 | +import java.math.BigDecimal; |
| 20 | +import static java.math.RoundingMode.HALF_UP; |
| 21 | + |
| 22 | +/** |
| 23 | + * {@code Product} class represents properties and behavior of product objects |
| 24 | + * in the Product Management System |
| 25 | + * <br> |
| 26 | + * Each product has an id, name, and price |
| 27 | + * <br> |
| 28 | + * Each product can have a discount, calculated based on a |
| 29 | + * {@link DISCOUNT_RATE discount_rate} |
| 30 | + * @version 1.0 |
| 31 | + * @author fullarray |
| 32 | + */ |
| 33 | +public class Product { |
| 34 | + /** |
| 35 | + * A constant that defines a |
| 36 | + * {@link java.math.BigDecimal BigDecimal} value of the discount rate |
| 37 | + * <br> |
| 38 | + * Discount rate is 10% |
| 39 | + */ |
| 40 | + public static final BigDecimal DISCOUNT_RATE = BigDecimal.valueOf(0.1); |
| 41 | + private int id; |
| 42 | + private String name; |
| 43 | + private BigDecimal price; |
| 44 | + |
| 45 | + public int getId() { |
| 46 | + return id; |
| 47 | + } |
| 48 | + |
| 49 | + public void setId(int id) { |
| 50 | + this.id = id; |
| 51 | + } |
| 52 | + |
| 53 | + public String getName() { |
| 54 | + return name; |
| 55 | + } |
| 56 | + |
| 57 | + public void setName(final String name) { |
| 58 | + this.name = name; |
| 59 | + } |
| 60 | + |
| 61 | + public BigDecimal getPrice() { |
| 62 | + return price; |
| 63 | + } |
| 64 | + |
| 65 | + public void setPrice(final BigDecimal price) { |
| 66 | + this.price = price; |
| 67 | + } |
| 68 | + /** |
| 69 | + * Calculates discount based on a product price and |
| 70 | + * {@link DISCOUNT_RATE discount_rate} |
| 71 | + * @return s {@link java.math.BigDecimal BigDecimal} |
| 72 | + * value of the discount |
| 73 | + */ |
| 74 | + public BigDecimal getDiscount(){ |
| 75 | + return price.multiply(DISCOUNT_RATE).setScale(2,HALF_UP); |
| 76 | + } |
| 77 | +} |
0 commit comments