Skip to content

Commit c8e04a3

Browse files
authored
Add files via upload
1 parent 8364ff5 commit c8e04a3

2 files changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.app;
18+
19+
import java.math.BigDecimal;
20+
import labs.pm.data.Product;
21+
22+
/**
23+
* {@code Shop} class represents an application that manages products
24+
* @version 1.0
25+
* @author fullarray
26+
*/
27+
public class Shop {
28+
29+
/**
30+
* @param args the command line arguments
31+
*/
32+
public static void main(String[] args) {
33+
// TODO code application logic here
34+
Product p1 = new Product();
35+
p1.setId(101);
36+
p1.setName("Tea");
37+
p1.setPrice(BigDecimal.valueOf(1.99));
38+
System.out.println(p1.getId() + " "+ p1.getName() + " "+ p1.getPrice()+" "+ p1.getDiscount());
39+
}
40+
41+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Comments
 (0)