Skip to content

Commit 150c57b

Browse files
committed
task2909. Рефакторинг 8
1 parent de96150 commit 150c57b

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed

3.JavaMultithreading/src/com/javarush/task/task29/task2909/human/Human.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.List;
66

77
public class Human implements Alive{
8-
public static int nextId = 0;
8+
private static int nextId = 0;
99
private int id;
1010
protected int age;
1111
protected String name;
@@ -77,10 +77,6 @@ public int getId() {
7777
return id;
7878
}
7979

80-
public void setId(int id) {
81-
this.id = id;
82-
}
83-
8480
public void printSize() {
8581
System.out.println("Рост: " + size[0] + " Вес: " + size[1]);
8682
}

3.JavaMultithreading/src/com/javarush/task/task29/task2909/human/Student.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ public void live() {
2424
public void learn() {
2525
}
2626

27+
// public void incAverageGradeBy01() {
28+
// averageGrade += 0.1;
29+
// }
30+
//
31+
// public void incAverageGradeBy02() {
32+
// averageGrade += 0.2;
33+
// }
34+
2735
public void incAverageGrade(double delta){
2836
averageGrade += delta;
2937
}

3.JavaMultithreading/src/com/javarush/task/task29/task2909/human/StudentsDataBase.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,37 @@
44
import java.util.List;
55

66
public class StudentsDataBase {
7-
public static List<Student> students = new ArrayList<>();
8-
9-
10-
public static void addInfoAboutStudent(Student student) {
11-
students.add(student);
12-
printInfoAboutStudent(student);
7+
public static List<Student> students = new ArrayList<>();
8+
9+
public static void addInfoAboutStudent(Student student) {
10+
students.add(student);
11+
printInfoAboutStudent(student);
12+
}
13+
14+
public static void printInfoAboutStudent(Student student) {
15+
System.out.println("Имя: " + student.name + " Возраст: " + student.getAge());
16+
}
17+
18+
public static void removeStudent(int index) {
19+
try{
20+
students.remove(index);
21+
} catch (Exception e) {
22+
// Do nothing
1323
}
1424

15-
public static void printInfoAboutStudent(Student student) {
16-
System.out.println("Имя: " + student.name + " Возраст: " + student.getAge());
17-
}
25+
}
1826

19-
public static void removeStudent(int index) throws IndexOutOfBoundsException {
20-
students.remove(index);
21-
}
27+
public static void findDimaOrSasha() {
28+
for (int i = 0; i < students.size(); i++) {
29+
if (students.get(i).getName().equals("Dima")) {
30+
System.out.println("Студент Dima есть в базе.");
31+
break;
32+
}
2233

23-
public static void findDimaOrSasha() {
24-
boolean found = false;
25-
for (int i = 0; i < students.size(); i++) {
26-
if (!found) {
27-
if (students.get(i).getName().equals("Dima")) {
28-
System.out.println("Студент Dima есть в базе.");
29-
found = true;
30-
}
31-
32-
if (students.get(i).getName().equals("Sasha")) {
33-
System.out.println("Студент Sasha есть в базе.");
34-
found = true;
35-
}
36-
}
37-
}
34+
if (students.get(i).getName().equals("Sasha")) {
35+
System.out.println("Студент Sasha есть в базе.");
36+
break;
37+
}
3838
}
39-
}
39+
}
40+
}

0 commit comments

Comments
 (0)