forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProduct.java
More file actions
44 lines (36 loc) · 851 Bytes
/
Product.java
File metadata and controls
44 lines (36 loc) · 851 Bytes
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
public class Product
{
String name;
int quantityInStock;
public Product(String name)
{
this.name = name;
}
public void stock(int amount)
{
int addingAmount = amount;
quantityInStock = quantityInStock + addingAmount;
}
public void sell(int amount)
{
int subtractingAmount = amount;
quantityInStock = quantityInStock - subtractingAmount;
}
public void recordLoss(int amount)
{
int subtractingAmount = amount;
quantityInStock = quantityInStock - subtractingAmount;
}
public String getName()
{
return name;
}
public int getQuantityInStock()
{
return quantityInStock;
}
public String toString()
{
return "Product: " + name + ", has a quantity of " + quantityInStock + ".";
}
}