-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoice.java
94 lines (71 loc) · 1.63 KB
/
Invoice.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
public class Invoice {
private String number;
private String description;
private int quantity;
private double price;
public Invoice() //initialize four variables
{
this.number = "null";
this.description = "null";
this.quantity = 0;
this.price = 0.0;
}
//initialize four variables with parameterized constructor
//and if you use parameterized constructor no need to use set and get method
public Invoice(String number,String description,int quantity,double price) {
this.number = number;
this.description = description;
this.quantity = quantity;
this.price = price;
}
/*setting values inside private variables of Class with set method
for the the Class's object get method call.
and returning them with get method for the the Class's object get method call.
*/
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getQuantity() {
if(quantity < 0)
return 0;
else {
return quantity;
}
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public double getPrice() {
if(price < 0)
return 0.0;
else{
return price;
}
}
public void setPrice(double price) {
this.price = price;
}
public double getInvoiceAmount()
{
return quantity*price;
}
//please use this if you use parameterized constructor
/*public double getInvoiceAmount()
{
if(price < 0)
price = 0.0;
if(quantity <0)
quantity = 0;
return quantity*price;
}
*/
}