-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.java
132 lines (117 loc) · 3.24 KB
/
Item.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* @author Phichayut Ngoennim [6388035] >>> MAIN CONTRIBUTOR
* @author Jirayu Klinudom [6388085]
* @author Perakorn Nimitkul [6388127]
* Section 2
*
* @status >>>TASK 1 COMPLETED
* >>>TASK 5 COMPLETED
* >>>PROJECT CONCLUDED
* >>>CHALLENGE CONCLUDED
*
* @Note >>>Nothing much to say here just followed the instruction
* and run the test case successfully
* >>>Not much fixing to be made on task 5
*/
public class Item implements Loggable{
//**************************** DO NOT MODIFY **********************************//
private String name; // item's name
private double price; // item's price
private boolean taxable = false; // default value is false (non-taxable)
private int qty = Integer.MAX_VALUE; // default value is unlimited supply (max_value)
//*****************************************************************************//
/**
* Constructor to initialize name, price
* @param name
* @param price
*/
public Item(String name, double price)
{
this.name = name;
this.price = price;
}
/**
* Constructor to initialize name, price, and taxable value
* @param name
* @param price
* @param taxable
*/
public Item(String name, double price, boolean taxable)
{
this.name = name;
this.price = price;
this.taxable = taxable;
}
/**
* Constructor to initialize, price, taxable, and remaining quantity in the stock
* @param name
* @param price
* @param taxable
* @param qty
*/
public Item(String name, double price, boolean taxable, int qty)
{
this.name = name;
this.price = price;
this.taxable = taxable;
this.qty = qty;
}
//*****************************************************************************//
/**
* Return true if the quantity of the item is larger than 0
* @return
*/
public boolean isAvailable()
{
return this.qty > 0;
}
/**
* Decrease the quantity by one
* @return remaining quantity in the stock
*/
public int sold()
{
this.qty -= 1;
return this.qty;
}
/**
* Increase the quantity by one
* @return remaining quantity in the stock
*/
public int restock()
{
this.qty += 1;
return this.qty;
}
/**
*
* @return string of completed data
*/
@Override
public String log()
{
String credits = df.format(this.price);
return this.name + "," + credits + "," + this.taxable + "," + this.qty;
}
//**************************** DO NOT MODIFY **********************************//
public String getName(){
return name;
}
public double getPrice(){
return price;
}
public boolean getTaxable(){
return taxable;
}
public int getQuantity(){
return qty;
}
@Override
public String toString(){
return "name::" + name
+ ",price::" + price
+ ",taxable::" + taxable
+ ",qty::" + qty;
}
//*****************************************************************************//
}