-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
340 lines (315 loc) · 7.38 KB
/
Main.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/**
* Work with classes.
* @author Vadim Chernyavsky
* @version v1.0
*/
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
/**
* Main class.
*/
public class Main {
/**
* The entry point of application.
*
* @param args the input arguments
* @throws IOException the io exception
*/
public static void main(String[] args) throws IOException {
System.out.println("Users:");
User myDefaultUser = new User();
System.out.println(myDefaultUser.toStr());
User myUser = new User(111, "Petrov", "Petr", "88005553535", "Junior Android Developer");
System.out.println(myUser.toStr());
System.out.println("---------------------------------------");
System.out.println("Individual person:");
Individual myDefaultIndividual = new Individual();
System.out.println(myDefaultIndividual.toStr());
Individual myIndividual = new Individual(222, "Kirillov", "Kirill", "2132131", "Cleaner");
System.out.println(myIndividual.toStr());
System.out.println("Company:");
Company myDefaultCompany = new Company();
System.out.println(myDefaultCompany.toStr());
Company myCompany = new Company(333, "Google", "Vadimov", "Vadim", "1232113", "Logist");
System.out.println(myCompany.toStr());
System.out.println("---------------------------------------");
System.out.println("Write to memory from file:");
FileWriter fileWriter = new FileWriter("file.txt");
fileWriter.write("121\nDanilov\nDanil\n12321312\nArchiver\n");
fileWriter.close();
FileReader fileReader = new FileReader("file.txt");
Scanner scan = new Scanner(fileReader);
int i = 0;
while(scan.hasNextLine()) {
switch(i) { //scan.nextLine() from every string
case 0 : {
myUser.setId(Integer.parseInt(scan.nextLine()));
break;
}
case 1 : {
myUser.setSurname(scan.nextLine());
break;
}
case 2 : {
myUser.setName(scan.nextLine());
break;
}
case 3 : {
myUser.setPhone(scan.nextLine());
break;
}
case 4 : {
myUser.setJob(scan.nextLine());
break;
}
}
i++;
}
System.out.println(myUser.toStr());
}
}
/**
* The class Env.
*/
class ENV{
/**
* The User id.
*/
static int USER_ID = 1;
/**
* The Company id.
*/
static int COMPANY_ID = 1;
/**
* The Individual id.
*/
static int INDIVIDUAL_ID = 1;
}
/**
* The class User.
*/
class User {
private int id;
private String surname;
private String name;
private String phone;
private String job;
/**
* Instantiates a new User.
*/
User(){
this.id = ENV.USER_ID;
ENV.USER_ID++;
this.surname = "Ivanov";
this.name = "Ivan";
this.phone = "2000000";
this.job = "Janitor";
}
/**
* Instantiates a new User.
*
* @param id the id
* @param surname the surname
* @param name the name
* @param phone the phone
* @param job the job
*/
User(int id,
String surname,
String name,
String phone,
String job){
this.id = id;
this.surname = surname;
this.name = name;
this.phone = phone;
this.job = job;
}
/**
* To str string.
*
* @return the string
*/
String toStr(){
return id + " " + surname + " " + name + " " + phone + " " + job;
}
/**
* Gets id.
*
* @return the id
*/
public int getId() {
return id;
}
/**
* Gets surname.
*
* @return the surname
*/
public String getSurname() {
return surname;
}
/**
* Gets name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Gets phone.
*
* @return the phone
*/
public String getPhone() {
return phone;
}
/**
* Gets job.
*
* @return the job
*/
public String getJob() {
return job;
}
/**
* Sets id.
*
* @param id the id
*/
public void setId(int id) {
this.id = id;
}
/**
* Sets surname.
*
* @param surname the surname
*/
public void setSurname(String surname) {
this.surname = surname;
}
/**
* Sets name.
*
* @param name the name
*/
public void setName(String name) {
this.name = name;
}
/**
* Sets phone.
*
* @param phone the phone
*/
public void setPhone(String phone) {
this.phone = phone;
}
/**
* Sets job.
*
* @param job the job
*/
public void setJob(String job) {
this.job = job;
}
}
/**
* The class Individual (person).
*/
class Individual {
private int id;
private String surname;
private String name;
private String phone;
private String job;
/**
* Instantiates a new Individual.
*/
Individual(){
this.id = ENV.INDIVIDUAL_ID;
ENV.INDIVIDUAL_ID++;
this.surname = "Timofeev";
this.name = "Timofei";
this.phone = "2111111";
this.job = "Cooker";
}
/**
* Instantiates a new Individual.
*
* @param id the id
* @param surname the surname
* @param name the name
* @param phone the phone
* @param job the job
*/
Individual(int id,
String surname,
String name,
String phone,
String job){
this.id = id;
this.surname = surname;
this.name = name;
this.phone = phone;
this.job = job;
}
/**
* To str string.
*
* @return the string
*/
String toStr(){
return "individual person - " + surname + " " + name + " " + phone + " " + job;
}
}
/**
* The class Company with extends Individual.
*/
class Company extends Individual{
private int id;
private String companyName;
private String surname;
private String name;
private String phone;
private String job;
/**
* Instantiates a new Company.
*/
Company(){
super();
this.id = ENV.COMPANY_ID;
ENV.COMPANY_ID++;
this.companyName = "Eltex";
}
/**
* Instantiates a new Company.
*
* @param id the id
* @param companyName the company name
* @param surname the surname
* @param name the name
* @param phone the phone
* @param job the job
*/
Company(int id,
String companyName,
String surname,
String name,
String phone,
String job){
super(id, surname, name, phone, job);
this.id = id;
this.companyName = companyName;
}
/**
* To str string.
*
* @return the string.
*/
String toStr() {
return this.id + " " + "company - " + this.companyName + ", " + super.toStr();
}
}