Skip to content

Commit b86b290

Browse files
authored
Philip said to him, "Lord"
Philip said to him, "Lord, show us the Father, and that will be enough for us." (John 14:8)
1 parent 3578139 commit b86b290

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

task13/task1306/Solution.java

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.javarush.task.task13.task1306;
2+
3+
//Philip said to him, "Lord, show us the Father, and that will be enough for us." (John 14:8)
4+
5+
/*
6+
Баг в initializeIdAndName
7+
*/
8+
9+
public class Solution {
10+
public static void main(String[] args) throws Exception {
11+
System.out.println(Matrix.NEO);
12+
System.out.println(Matrix.TRINITY);
13+
}
14+
15+
static class Matrix {
16+
public static DBObject NEO = new User().initializeIdAndName(1, "Neo");
17+
public static DBObject TRINITY = new User().initializeIdAndName(2, "Trinity");
18+
}
19+
20+
interface DBObject {
21+
User initializeIdAndName(long id, String name);
22+
}
23+
24+
static class User implements DBObject {
25+
long id;
26+
String name;
27+
28+
@Override
29+
public String toString() {
30+
return String.format("User has name %s, id = %d", name, id);
31+
}
32+
33+
@Override
34+
public User initializeIdAndName (long id, String name) {
35+
this.id = id;
36+
this.name = name;
37+
return new User();
38+
}
39+
40+
}
41+
42+
}
43+
44+
45+
46+
47+
48+
49+
/*
50+
Баг в initializeIdAndName
51+
1. Подумать, что в программе неправильно.
52+
2. Вынести реализацию метода initializeIdAndName в класс User.
53+
3. initializeIdAndName в классе User должен возвращать тип User.
54+
4. Поправить программу, чтобы компилировалась и работала.
55+
56+
57+
Требования:
58+
1. Интерфейс DBObject должен содержать только объявление метода initializeIdAndName без реализации.
59+
2. Реализуй метод initializeIdAndName в классе User.
60+
3. Метод initializeIdAndName в классе User должен иметь тип возвращаемого значения User.
61+
4. Метод initializeIdAndName должен присваивать значения полям id и name в соответствии с переданными ему параметрами.
62+
63+
package com.javarush.task.task13.task1306;
64+
65+
/*
66+
Баг в initializeIdAndName
67+
*/
68+
69+
public class Solution {
70+
public static void main(String[] args) throws Exception {
71+
System.out.println(Matrix.NEO);
72+
System.out.println(Matrix.TRINITY);
73+
}
74+
75+
static class Matrix {
76+
public static DBObject NEO = new User().initializeIdAndName(1, "Neo");
77+
public static DBObject TRINITY = new User().initializeIdAndName(2, "Trinity");
78+
}
79+
80+
interface DBObject {
81+
DBObject initializeIdAndName(long id, String name) {
82+
this.id = id;
83+
this.name = name;
84+
return this;
85+
}
86+
}
87+
88+
static class User implements DBObject {
89+
long id;
90+
String name;
91+
92+
@Override
93+
public String toString() {
94+
return String.format("User has name %s, id = %d", name, id);
95+
}
96+
}
97+
98+
}
99+
*/

0 commit comments

Comments
 (0)