-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path$7_Classes.java
More file actions
93 lines (72 loc) · 1.97 KB
/
$7_Classes.java
File metadata and controls
93 lines (72 loc) · 1.97 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
package src;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class $7_Classes {
public static void main(String[] args) {
String csvFilePath = "src/$7_Classes.csv";
String currentLine;
String delimitComma = ",";
PersonsRestrictedModel classPerson = null;
PersonsRestrictedModel classPerson2 = null;
try (BufferedReader reader = new BufferedReader(new FileReader(csvFilePath))) {
boolean isFirstLine = true;
while ((currentLine = reader.readLine()) != null) {
if (isFirstLine) {
isFirstLine = false;
continue;
}
String[] data = currentLine.split(delimitComma);
String name = data[0];
int age = Integer.parseInt(data[1]);
String email = data[2];
classPerson = new PersonsRestrictedModel(name, age, email);
if (classPerson.getName().equals("Bob Johnson")) {
System.out.println(classPerson.getEmail());
}
classPerson2 = new PersonsRestrictedModel(name, age, email);
int age2 = classPerson2.getAge();
if (age2 > 30 && age2 < 40) {
System.out.println(classPerson2.getAge());
}
}
classPerson2.setAge(50);
classPerson2.setName("Mary Smith");
System.out.println(classPerson2.getAge());
System.out.println(classPerson2.getName());
System.out.println(classPerson2.getEmail());
System.out.println(classPerson.getEmail());
} catch (IOException errorMessage) {
errorMessage.printStackTrace();
}
}
}
class PersonsRestrictedModel { // class
private String name;
private int age;
private String email;
public PersonsRestrictedModel(String name, int age, String email) { // class constructor
this.name = name;
this.age = age;
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}