-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShop.java
121 lines (103 loc) · 3.06 KB
/
Shop.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
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class Shop {
private ArrayList<Order> orders;
private File orderFile;
private String fileName;
private ArrayList<Supplier> suppliers;
private Inventory inv;
private int orderIndex;
public Shop (Inventory i, ArrayList<Supplier> s, ArrayList<Order> orders)
{
this.suppliers = s;
this.inv = i;
this.orders = orders;
fileName = "orders.txt";
orderFile = new File (fileName);
orderIndex = -1;
}
public void addInvFromFile(String filename) throws IOException
{
inv.addItemsFromFile(filename);
assignItemsToSupplier();
createOrderFile();
inventoryOrder();
}
public void addSuppliersFromFile(String fileName) throws IOException
{
FileInputStream fileIn= new FileInputStream(fileName);
BufferedReader read = new BufferedReader(new InputStreamReader(fileIn));
String line = read.readLine();
while (line != null){
Supplier a = readValues(line);
suppliers.add(a);
line = read.readLine();
}
}
public Supplier readValues(String r)
{
Scanner s = new Scanner(r).useDelimiter(";");
int id = s.nextInt();
String companyName = s.next();
String address = s.next();
String salesContact = s.next();
return new Supplier (id, companyName, address, salesContact);
}
public void createOrderFile() throws IOException
{
orderFile.createNewFile();
PrintWriter write = new PrintWriter(fileName);
write.close();
}
public void inventoryOrder()throws FileNotFoundException
{
boolean check = inv.checkIfOrder();
if (check) {
Order o = new Order (orderFile);
orders.add(o);
orderIndex++;
if (orderIndex==0)
inv.generateOrder(o, true);
else
inv.generateOrder(o, orderDateCheck(o));
}
}
public boolean orderDateCheck(Order o)
{
if (o.getDateString().equals(orders.get(orderIndex-1).getDateString())){
return false;
}
return true;
}
public int sell(int id, int quantity)throws FileNotFoundException
{
int check = inv.decreaseItemQuan(id, quantity);
inventoryOrder();
return check;
}
public String getItemInfo(int id)
{
return inv.getItemInfo(id);
}
public String getItemInfo(String desc)
{
return inv.getItemInfo(desc);
}
public void printInventory()
{
inv.printAllItems();
}
public void assignItemsToSupplier()
{
for (Supplier s: suppliers) {
s.addItem(inv.getItems());
}
}
public void closeOrderFile()throws FileNotFoundException
{
PrintWriter write = new PrintWriter (new FileOutputStream(orderFile, true));
write.println("**********************************************************************");
write.close();
}
}