forked from Kitch05/Vending-Machine-with-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.java
More file actions
81 lines (72 loc) · 1.93 KB
/
Copy pathItem.java
File metadata and controls
81 lines (72 loc) · 1.93 KB
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
import java.util.ArrayList;
/**
* This class represents a single unique item.
*/
public abstract class Item {
private String name;
private double price;
private double calories;
protected ArrayList<Item> stock;
/**
* Class constructor that creates the object from scratch.
*
* @param name name of the item.
* @param price price of the item.
* @param calories amount of calories contained in the item.
*/
public Item(String name, double price, double calories) {
this.name = name;
this.price = price;
this.calories = calories;
this.stock = new ArrayList<Item>();
}
/**
* Returns the item name.
*
* @return a string.
*/
public String getName() {
return name;
}
/**
* Returns the price of the item.
*
* @return a double.
*/
public double getPrice() {
return price;
}
/**
* Allows the user to set a new price to the item.
*
* @param price the new price of the item.
*/
public void setPrice(double price) {
this.price = price;
}
/**
* Returns the calories contained in the item.
*
* @return a double.
*/
public double getCalories() {
return calories;
}
/**
* Returns the details of the item as a string.
*
* @return a string.
*/
public String toString() {
return String.format("Item: %-10s Price: %-10.2f Calories: %-10.2f", this.name, this.price, this.calories);
}
/**
* Meant to add a new item of the same type as the subclass that invokes this
*/
public abstract void addItem();
/**
* Meant to get the array list that acts as the stock of the subclass item object.
* @return an array list
*/
public abstract ArrayList<Item> getStock();
}