-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.java
171 lines (163 loc) · 3.82 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* CS-112 FINAL PROJECT
File Name: Item.java
Programmer: James Watkins
Date Last Modified: May 19, 2012
Problem Statement: Define a class to contain the specific details of items
which will be used within an inventory management application. Class must
account for image files as well as text and numeric variables. Enable
binary I/O.
Overall Plan:
1. Define the constructors which will be used to create Item objects.
2. Provide mutator and accessor methods for each of an Item's variables.
3. Override equals.
4. Override toString.
5. Make the class serializable to support binary I/O operations.
Classes needed and Purpose (Input, Processing, Output)
NumberFormat - output
String - input, output
*/
import java.text.NumberFormat;
import java.io.Serializable;
import java.io.*;
public class Item implements Serializable
{
private String description, model, maker, serialNumber, pictureFileName;
private int quantity, yearPurchased;
private double price;
NumberFormat money = NumberFormat.getCurrencyInstance();
public Item()
{
description = null;
model = null;
maker = null;
serialNumber = null;
quantity = 0;
yearPurchased = 1000;
price = 0.0;
pictureFileName = null;
}
public Item(String descr, String aModel, String make, String SN, int QTY,
int datePurchase, double aPrice)
{
description = descr;
model = aModel;
maker = make;
serialNumber = SN;
quantity = QTY;
yearPurchased = datePurchase;
price = aPrice;
pictureFileName = null;
}
public Item(String descr, String aModel, String make, String SN, int QTY,
int datePurchase, double aPrice, String picFile)
{
description = descr;
model = aModel;
maker = make;
serialNumber = SN;
quantity = QTY;
yearPurchased = datePurchase;
price = aPrice;
pictureFileName = picFile;
}
public void updateAll(String descr, String aModel, String make,
String SN, int QTY, int datePurchase, double aPrice, String picFile)
{
description = descr;
model = aModel;
maker = make;
serialNumber = SN;
quantity = QTY;
yearPurchased = datePurchase;
price = aPrice;
pictureFileName = picFile;
}
public void setPic(String fileName)
{
pictureFileName = fileName;
}
public String getPic()
{
return pictureFileName;
}
public void setDescription(String descr)
{
description = descr;
}
public String getDescription()
{
return description;
}
public void setModel(String input)
{
model = input;
}
public String getModel()
{
return model;
}
public void setMake(String input)
{
maker = input;
}
public String getMake()
{
return maker;
}
public void setSerial(String SN)
{
serialNumber = SN;
}
public String getSerial()
{
return serialNumber;
}
public void setQty(int QTY)
{
quantity = QTY;
}
public int getQty()
{
return quantity;
}
public void setDate(int datePurchase)
{
yearPurchased = datePurchase;
}
public int getDate()
{
return yearPurchased;
}
public void setPrice(double aPrice)
{
price = aPrice;
}
public double getPrice()
{
return price;
}
public boolean equals(Item other)
{
boolean flag;
if (this == other)
flag = true;
//assumes that purchase price, and purchase date do not make an item unique
else if ((description.equalsIgnoreCase(other.description))&&
(serialNumber.equalsIgnoreCase(other.serialNumber))&&
(model.equalsIgnoreCase(other.model))&&
(maker.equalsIgnoreCase(other.maker)))
flag = true;
else
//items are not identical
flag = false;
return flag;
}
public String toString()
{
return ("Description:\t"+description+"\nManufacturer:\t"+maker+
"\nModel Number:\t"+model+"\nSerial Number:\t"+serialNumber+
"\nYear Purchased:\t"+yearPurchased+"\nQuantity:\t"+quantity+
"\t\tPurchase Price:\t"+ money.format(price) +
"\nPicture file:\t" + pictureFileName + "\n");
}
}