-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBranch.java
More file actions
159 lines (138 loc) · 5.59 KB
/
Copy pathBranch.java
File metadata and controls
159 lines (138 loc) · 5.59 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
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment.pkg1;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JTextArea;
/**
*
* @author Simon
*/
public class Branch {
private IAddress BranchAddress;
private String WorkingHours;
private String SortCode;
private String Manager;
private String Filename;
public Branch() {
Filename = "HeadOffice.txt";
BranchAddress = new IAddress();
}
public String ArrayListtoString() {
StringBuilder result = new StringBuilder();
result.append(BranchAddress.getName() + "," + BranchAddress.getStreet() + "," + BranchAddress.getArea() + "," + BranchAddress.getPostCode() + "," + BranchAddress.getTown() + "," + BranchAddress.getCountry() + "," + SortCode + "," + Manager + "," + WorkingHours + System.getProperty("line.separator"));
return result.toString();
}
public void Display(javax.swing.JTextArea jAddressTextArea) {
jAddressTextArea.setLineWrap(true);
jAddressTextArea.append("Branch Name: " + BranchAddress.getName() + "\n");
jAddressTextArea.append("Street: " + BranchAddress.getStreet() + "\n");
jAddressTextArea.append("Area: " + BranchAddress.getArea() + "\n");
jAddressTextArea.append("Postcode: " + BranchAddress.getPostCode() + "\n");
jAddressTextArea.append("Town: " + BranchAddress.getTown() + "\n");
jAddressTextArea.append("Country: " + BranchAddress.getCountry() + "\n");
jAddressTextArea.append("Sort Code: " + SortCode + "\n");
jAddressTextArea.append("Manager: " + Manager + "\n");
jAddressTextArea.append("Opening Hours: " + WorkingHours + "\n");
}
public void Edit(String AddressName, String StreetName, String AreaName, String PostCodeName, String TownName, String CountryName, String SortCodeName, String ManagerName, String WorkingHoursName) {
BranchAddress.setName(AddressName);
BranchAddress.setStreet(StreetName);
BranchAddress.setArea(AreaName);
BranchAddress.setPostCode(PostCodeName);
BranchAddress.setTown(TownName);
BranchAddress.setCountry(CountryName);;
SortCode = SortCodeName;
Manager = ManagerName;
WorkingHours = WorkingHoursName;
}
public void LoadFromFile() {
int i = 0;
String record;
FileReader reader;
try {
reader = new FileReader(Filename);
BufferedReader bin = new BufferedReader(reader);
record = new String();
while ((record = bin.readLine()) != null) {
i++;
if (i == 1) {
BranchAddress.setName(record);
} else if (i == 2) {
BranchAddress.setStreet(record);
} else if (i == 3) {
BranchAddress.setArea(record);
} else if (i == 4) {
BranchAddress.setPostCode(record);
} else if (i == 5) {
BranchAddress.setTown(record);
} else if (i == 6) {
BranchAddress.setCountry(record);
} else if (i == 7) {
SortCode = record;
} else if (i == 8) {
Manager = record;
} else if (i == 9) {
WorkingHours = record;
}
}
bin.close();
bin = null;
} catch (IOException ioe) {
}
}
public void SaveToFile() {
FileWriter writer;
try {
writer = new FileWriter(Filename, false);
writer.write(BranchAddress.getName() + System.getProperty("line.separator"));
writer.write(BranchAddress.getStreet() + System.getProperty("line.separator"));
writer.write(BranchAddress.getArea() + System.getProperty("line.separator"));
writer.write(BranchAddress.getPostCode() + System.getProperty("line.separator"));
writer.write(BranchAddress.getTown() + System.getProperty("line.separator"));
writer.write(BranchAddress.getCountry() + System.getProperty("line.separator"));
writer.write(SortCode + System.getProperty("line.separator"));
writer.write(Manager + System.getProperty("line.separator"));
writer.write(WorkingHours + System.getProperty("line.separator"));
writer.flush();
writer.close();
writer = null;
} catch (IOException ioe) {
}
}
public String getBranchName() {
return BranchAddress.getName();
}
public void setBranchName(String strBranchName) {
BranchAddress.setName(strBranchName);
}
public void setStreet(String strStreet) {
BranchAddress.setStreet(strStreet);
}
public void setArea(String strArea) {
BranchAddress.setArea(strArea);
}
public void setPostCode(String strPostCode) {
BranchAddress.setPostCode(strPostCode);
}
public void setTown(String strTown) {
BranchAddress.setTown(strTown);
}
public void setCountry(String strCountry) {
BranchAddress.setCountry(strCountry);
}
public void setSortCode(String strSortCode) {
SortCode = strSortCode;
}
public void setManager(String strManager) {
Manager = strManager;
}
public void setWorkingHours(String strWorkingHours) {
WorkingHours = strWorkingHours;
}
}