-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.java
More file actions
101 lines (90 loc) · 2.85 KB
/
Item.java
File metadata and controls
101 lines (90 loc) · 2.85 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* This class is a very simple representation of a hardware item. For parameters
* except <CODE>quantity</CODE>, there are only getter methods and no setter methods as
* basic info of an item cannot be mutated once initialized.
*
* An item object can also call the override methods
* <CODE>equals()</CODE>
*
* @author Ryan Franklin and Tory Brewer
*
*/
import java.io.Serializable;
public abstract class Item implements Serializable {
protected final String idNumber;
protected final String name;
protected int quantity;
protected final float price;
/**
* This constructor initializes the item object. The constructor provides no
* user input validation. That should be handled by the class that creates a
* item object.
*
* @param idNumber a <b><CODE>String</CODE></b> that represents the ID
* random string of length 5 – can contain letters and numbers
* @param name a <b><CODE>String</CODE></b> that represents the name
* @param price an <b><CODE>float</CODE></b> that represents the price
*/
public Item(String idNumber, String name, int quantity, float price) {
this.idNumber = idNumber;
this.name = name;
this.quantity = quantity;
this.price = price;
}
/**
* This method returns the item's tracking number.
*
* @return a <b><CODE>String</CODE></b> that is the ID number of the item.
*/
public String getIdNumber() {
return idNumber;
}
/**
* This method returns the item's name.
*
* @return a <b><CODE>String</CODE></b> that is the item's name.
*/
public String getName() {
return name;
}
/**
* This method returns the item's quantity.
*
* @return an <b><CODE>int</CODE></b> that is the item's weight
*/
public int getQuantity() {
return quantity;
}
/**
* This method set the item's quantity.
*
* @param quantity a <b><CODE>int</CODE></b> that represents the quantity
*/
public void setQuantity(int quantity) {
this.quantity= quantity;
}
/**
* This method returns the item's price.
*
* @return a <b><CODE>float</CODE></b> that is the item's price
*/
public float getPrice() {
return price;
}
/**
* This method provides a way to compare two item objects.
*
* @param c a <b><CODE>Item</CODE></b> object that is used to compare to
* <b><CODE>this</CODE></b> item. Two orders are equal if their ID is the
* same.
* @return the <CODE>boolean</CODE> value of the comparison.
*/
public boolean equals(Item c) {
return c.getIdNumber().equals(this.idNumber);
}
/**
* Abstract print method, to be implemented by subclasses of class User.
* @return
*/
public abstract String getFormattedText();
}