Skip to content

Commit 0896714

Browse files
authored
have believed that I came forth from God
for the Father himself loves you, because you have loved me, and have believed that I came forth from God. (John 16:27)
1 parent a767650 commit 0896714

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

task17/task1704/Solution.java

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
//for the Father himself loves you, because you have loved me, and have believed that I came forth from God. (John 16:27)
3+
4+
5+
package com.javarush.task.task17.task1704;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
/*
11+
Синхронизированные заметки 2
12+
*/
13+
14+
public class Solution {
15+
16+
public static void main(String[] args) {
17+
18+
}
19+
20+
public static class Note {
21+
22+
public final List<String> notes = new ArrayList<String>();
23+
24+
public synchronized void addNote(int index, String note) {
25+
System.out.println("Сейчас будет добавлена заметка [" + note + "] На позицию " + index);
26+
27+
notes.add(index, note);
28+
29+
System.out.println("Уже добавлена заметка [" + note + "]");
30+
}
31+
32+
public synchronized void removeNote(int index) {
33+
System.out.println("Сейчас будет удалена заметка с позиции " + index);
34+
String note;
35+
36+
note = notes.remove(index);
37+
38+
System.out.println("Уже удалена заметка [" + note + "] с позиции " + index);
39+
}
40+
}
41+
}
42+
43+
44+
45+
46+
47+
/*
48+
Синхронизированные заметки 2
49+
Класс Note будет использоваться нитями. Поэтому сделай так, чтобы вcе методы были синхронизированы
50+
51+
52+
Требования:
53+
1. Метод addNote() должен добавлять записки в список notes.
54+
2. Метод removeNote() должен удалять записку из списка notes.
55+
3. Метод addNote() должен быть синхронизирован.
56+
4. Метод removeNote() должен быть синхронизирован.
57+
58+
59+
package com.javarush.task.task17.task1704;
60+
61+
import java.util.ArrayList;
62+
import java.util.List;
63+
64+
*
65+
Синхронизированные заметки 2
66+
*
67+
68+
public class Solution {
69+
70+
public static void main(String[] args) {
71+
72+
}
73+
74+
public static class Note {
75+
76+
public final List<String> notes = new ArrayList<String>();
77+
78+
public void addNote(int index, String note) {
79+
System.out.println("Сейчас будет добавлена заметка [" + note + "] На позицию " + index);
80+
notes.add(index, note);
81+
System.out.println("Уже добавлена заметка [" + note + "]");
82+
}
83+
84+
public void removeNote(int index) {
85+
System.out.println("Сейчас будет удалена заметка с позиции " + index);
86+
String note = notes.remove(index);
87+
System.out.println("Уже удалена заметка [" + note + "] с позиции " + index);
88+
}
89+
}
90+
}
91+
*/

0 commit comments

Comments
 (0)