-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrder.java
52 lines (43 loc) · 1.42 KB
/
Order.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
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class Order {
private PrintWriter fileWrite;
private File orderFile;
private ArrayList<OrderLine> orderLines;
private Date date;
private SimpleDateFormat format;
String dateString;
private int orderID;
public Order(File file)
{
orderFile = file;
orderLines = new ArrayList<OrderLine>();
date = new Date ();
format = new SimpleDateFormat("MMMM dd, yyyy");
dateString = format.format(date);
orderID = (int)(Math.random() * 90000) + 10000;
}
public void addLine(Item item)
{
OrderLine ol = new OrderLine(item);
orderLines.add(ol);
}
public void createOrder(boolean newLine) throws FileNotFoundException
{
fileWrite = new PrintWriter(new FileOutputStream(orderFile, true));
if (newLine) {
fileWrite.println("**********************************************************************");
fileWrite.println("ORDER ID:\t\t" + orderID + "\r\n" +
"Date Ordered:\t\t" + dateString);
}
for (OrderLine o: orderLines)
fileWrite.println(o);
fileWrite.close();
}
public String getDateString(){return dateString;}
}