質問編集履歴
2
恐れ入ります。<code>のなかに貼り付け致しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,237 +8,299 @@
|
|
8
8
|
|
9
9
|
### 該当のソースコード
|
10
10
|
|
11
|
+
```
|
12
|
+
|
11
13
|
package kadai18;
|
12
14
|
|
13
15
|
|
14
16
|
|
15
|
-
import java.util.Arrays;
|
17
|
+
import java.util.Arrays;
|
18
|
+
|
19
|
+
import java.util.HashMap;
|
20
|
+
|
21
|
+
import java.util.Map;
|
22
|
+
|
23
|
+
import java.util.Scanner;
|
24
|
+
|
25
|
+
import java.util.regex.Matcher;
|
26
|
+
|
27
|
+
import java.util.regex.Pattern;
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
public class K06 {
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
public static void main(String[] args) {
|
36
|
+
|
37
|
+
/**
|
38
|
+
|
39
|
+
* 社員番号と名前をMapに格納し、表示します。
|
40
|
+
|
41
|
+
*/
|
42
|
+
|
43
|
+
// TODO 自動生成されたメソッド・スタブ
|
44
|
+
|
45
|
+
Pattern p = Pattern.compile("-?\d+");
|
46
|
+
|
47
|
+
Map<String, Member> memberMap = new HashMap<String, Member>();
|
48
|
+
|
49
|
+
Scanner sc = new Scanner(System.in);
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
System.out.println("モード選択" + "\n" + "新規追加 -i" + "\n" + "変更 -u" + "\n" + "削除 -d" + "\n" + "一覧表示 -v" + "\n" + "ソート -s" + "\n" + "プログラム終了 -e");
|
54
|
+
|
55
|
+
String s = sc.next();
|
56
|
+
|
57
|
+
if (s.equals("-i")) {
|
58
|
+
|
59
|
+
s = "";
|
60
|
+
|
61
|
+
sc = new Scanner(System.in);
|
62
|
+
|
63
|
+
s = sc.next();
|
64
|
+
|
65
|
+
String[] splitMap = s.split(",");
|
66
|
+
|
67
|
+
Matcher matcher = p.matcher(splitMap[0]);
|
68
|
+
|
69
|
+
if(matcher.find()) {
|
70
|
+
|
71
|
+
if (memberMap.containsKey(splitMap[0])) {
|
72
|
+
|
73
|
+
s = "";
|
74
|
+
|
75
|
+
System.out.println(splitMap[0] + "はすでに入力されています");
|
76
|
+
|
77
|
+
s = sc.next();
|
78
|
+
|
79
|
+
if (s.equals("-m")) {
|
80
|
+
|
81
|
+
s = "";
|
82
|
+
|
83
|
+
System.out.println("モード選択" + "\n" + "新規追加 -i" + "\n" + "変更 -u" + "\n" + "削除 -d" + "\n" + "一覧表示 -v" + "\n" + "ソート -s" + "\n" + "プログラム終了 -e");
|
84
|
+
|
85
|
+
s = sc.next();
|
86
|
+
|
87
|
+
}else {
|
88
|
+
|
89
|
+
Member m = new Member(splitMap[1], splitMap[2]);
|
90
|
+
|
91
|
+
memberMap.put(splitMap[0], m);
|
92
|
+
|
93
|
+
s = "";
|
94
|
+
|
95
|
+
sc = new Scanner(System.in);
|
96
|
+
|
97
|
+
s = sc.next();
|
98
|
+
|
99
|
+
if (s.equals("-m")) {
|
100
|
+
|
101
|
+
s = "";
|
102
|
+
|
103
|
+
System.out.println("モード選択" + "\n" + "新規追加 -i" + "\n" + "変更 -u" + "\n" + "削除 -d" + "\n" + "一覧表示 -v" + "\n" + "ソート -s" + "\n" + "プログラム終了 -e");
|
104
|
+
|
105
|
+
s = sc.next();
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
if (s.equals("-u")) {
|
120
|
+
|
121
|
+
System.out.println("社員番号を入力して下さい。");
|
122
|
+
|
123
|
+
s = "";
|
124
|
+
|
125
|
+
s = sc.next();
|
126
|
+
|
127
|
+
if (memberMap.containsKey(s)) {
|
128
|
+
|
129
|
+
System.out.println("変更後の名前と部署名を「名前,部署名」で入力して下さい。");
|
130
|
+
|
131
|
+
s = "";
|
132
|
+
|
133
|
+
s = sc.next();
|
134
|
+
|
135
|
+
String[] alteredMap = s.split(",");
|
136
|
+
|
137
|
+
Member m1 = new Member(alteredMap[0], alteredMap[1]);
|
138
|
+
|
139
|
+
memberMap.put(s, m1 );
|
140
|
+
|
141
|
+
}else {
|
142
|
+
|
143
|
+
System.out.println("該当するデータはありません。");
|
144
|
+
|
145
|
+
s = "";
|
146
|
+
|
147
|
+
sc = new Scanner(System.in);
|
148
|
+
|
149
|
+
s = sc.next();
|
150
|
+
|
151
|
+
if (s.equals("-m")) {
|
152
|
+
|
153
|
+
s = "";
|
154
|
+
|
155
|
+
System.out.println("モード選択" + "\n" + "新規追加 -i" + "\n" + "変更 -u" + "\n" + "削除 -d" + "\n" + "一覧表示 -v" + "\n" + "ソート -s" + "\n" + "プログラム終了 -e");
|
156
|
+
|
157
|
+
s = sc.next();
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
if (s.equals("-d")) {
|
166
|
+
|
167
|
+
System.out.println("社員番号を入力して下さい。");
|
168
|
+
|
169
|
+
s = "";
|
170
|
+
|
171
|
+
s = sc.next();
|
172
|
+
|
173
|
+
if (memberMap.containsKey(s)) {
|
174
|
+
|
175
|
+
System.out.println("社員番号:" + s + " " + memberMap.get("s1").toString());
|
176
|
+
|
177
|
+
System.out.println("このデータを削除する場合は「y」、削除しない場合は「n」を入力して下さい。");
|
178
|
+
|
179
|
+
s = "";
|
180
|
+
|
181
|
+
s = sc.next();
|
182
|
+
|
183
|
+
if(s.equals("y")) {
|
184
|
+
|
185
|
+
memberMap.remove("s1");
|
186
|
+
|
187
|
+
}else if(s.equals("n")) {
|
188
|
+
|
189
|
+
s ="";
|
190
|
+
|
191
|
+
s = sc.next();
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
if (s.equals("-v")) {
|
200
|
+
|
201
|
+
s = "";
|
202
|
+
|
203
|
+
for (Map.Entry<String, Member> entry : memberMap.entrySet()) {
|
204
|
+
|
205
|
+
System.out.println("社員番号:" + entry.getKey() + " " + entry.getValue().toString());
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
System.out.println("表示完了");
|
210
|
+
|
211
|
+
s = sc.next();
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
if (s.equals("-m")) {
|
216
|
+
|
217
|
+
s = "";
|
218
|
+
|
219
|
+
System.out.println("モード選択" + "\n" + "新規追加 -i" + "\n" + "変更 -u" + "\n" + "削除 -d" + "\n" + "一覧表示 -v" + "\n" + "ソート -s" + "\n" + "プログラム終了 -e");
|
220
|
+
|
221
|
+
s = sc.next();
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
if (s.equals("-s")) {
|
226
|
+
|
227
|
+
Object[] mapkey = memberMap.keySet().toArray();
|
228
|
+
|
229
|
+
Arrays.sort(mapkey);
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
if (s.equals("-e")) {
|
234
|
+
|
235
|
+
System.exit(0);
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
```
|
16
246
|
|
17
247
|
package kadai18;
|
18
248
|
|
19
249
|
|
20
250
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
p
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
public
|
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
|
-
if (memberMap.containsKey(splitMap[0])) {
|
76
|
-
|
77
|
-
s = "";
|
78
|
-
|
79
|
-
System.out.println(splitMap[0] + "はすでに入力されています");
|
80
|
-
|
81
|
-
s = sc.next();
|
82
|
-
|
83
|
-
if (s.equals("-m")) {
|
84
|
-
|
85
|
-
s = "";
|
86
|
-
|
87
|
-
System.out.println("モード選択" + "\n" + "新規追加 -i" + "\n" + "変更 -u" + "\n" + "削除 -d" + "\n" + "一覧表示 -v" + "\n" + "ソート -s" + "\n" + "プログラム終了 -e");
|
88
|
-
|
89
|
-
s = sc.next();
|
90
|
-
|
91
|
-
}else {
|
92
|
-
|
93
|
-
Member m = new Member(splitMap[1], splitMap[2]);
|
94
|
-
|
95
|
-
memberMap.put(splitMap[0], m);
|
96
|
-
|
97
|
-
s = "";
|
98
|
-
|
99
|
-
sc = new Scanner(System.in);
|
100
|
-
|
101
|
-
s = sc.next();
|
102
|
-
|
103
|
-
if (s.equals("-m")) {
|
104
|
-
|
105
|
-
s = "";
|
106
|
-
|
107
|
-
System.out.println("モード選択" + "\n" + "新規追加 -i" + "\n" + "変更 -u" + "\n" + "削除 -d" + "\n" + "一覧表示 -v" + "\n" + "ソート -s" + "\n" + "プログラム終了 -e");
|
108
|
-
|
109
|
-
s = sc.next();
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
}
|
114
|
-
|
115
|
-
}
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
if (s.equals("-u")) {
|
124
|
-
|
125
|
-
System.out.println("社員番号を入力して下さい。");
|
126
|
-
|
127
|
-
s = "";
|
128
|
-
|
129
|
-
s = sc.next();
|
130
|
-
|
131
|
-
if (memberMap.containsKey(s)) {
|
132
|
-
|
133
|
-
System.out.println("変更後の名前と部署名を「名前,部署名」で入力して下さい。");
|
134
|
-
|
135
|
-
s = "";
|
136
|
-
|
137
|
-
s = sc.next();
|
138
|
-
|
139
|
-
String[] alteredMap = s.split(",");
|
140
|
-
|
141
|
-
Member m1 = new Member(alteredMap[0], alteredMap[1]);
|
142
|
-
|
143
|
-
memberMap.put(s, m1 );
|
144
|
-
|
145
|
-
}else {
|
146
|
-
|
147
|
-
System.out.println("該当するデータはありません。");
|
148
|
-
|
149
|
-
s = "";
|
150
|
-
|
151
|
-
sc = new Scanner(System.in);
|
152
|
-
|
153
|
-
s = sc.next();
|
154
|
-
|
155
|
-
if (s.equals("-m")) {
|
156
|
-
|
157
|
-
s = "";
|
158
|
-
|
159
|
-
System.out.println("モード選択" + "\n" + "新規追加 -i" + "\n" + "変更 -u" + "\n" + "削除 -d" + "\n" + "一覧表示 -v" + "\n" + "ソート -s" + "\n" + "プログラム終了 -e");
|
160
|
-
|
161
|
-
s = sc.next();
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
}
|
166
|
-
|
167
|
-
}
|
168
|
-
|
169
|
-
if (s.equals("-d")) {
|
170
|
-
|
171
|
-
System.out.println("社員番号を入力して下さい。");
|
172
|
-
|
173
|
-
s = "";
|
174
|
-
|
175
|
-
s = sc.next();
|
176
|
-
|
177
|
-
if (memberMap.containsKey(s)) {
|
178
|
-
|
179
|
-
System.out.println("社員番号:" + s + " " + memberMap.get("s1").toString());
|
180
|
-
|
181
|
-
System.out.println("このデータを削除する場合は「y」、削除しない場合は「n」を入力して下さい。");
|
182
|
-
|
183
|
-
s = "";
|
184
|
-
|
185
|
-
s = sc.next();
|
186
|
-
|
187
|
-
if(s.equals("y")) {
|
188
|
-
|
189
|
-
memberMap.remove("s1");
|
190
|
-
|
191
|
-
}else if(s.equals("n")) {
|
192
|
-
|
193
|
-
s ="";
|
194
|
-
|
195
|
-
s = sc.next();
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
}
|
202
|
-
|
203
|
-
if (s.equals("-v")) {
|
204
|
-
|
205
|
-
s = "";
|
206
|
-
|
207
|
-
for (Map.Entry<String, Member> entry : memberMap.entrySet()) {
|
208
|
-
|
209
|
-
System.out.println("社員番号:" + entry.getKey() + " " + entry.getValue().toString());
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
System.out.println("表示完了");
|
214
|
-
|
215
|
-
s = sc.next();
|
216
|
-
|
217
|
-
}
|
218
|
-
|
219
|
-
if (s.equals("-m")) {
|
220
|
-
|
221
|
-
s = "";
|
222
|
-
|
223
|
-
System.out.println("モード選択" + "\n" + "新規追加 -i" + "\n" + "変更 -u" + "\n" + "削除 -d" + "\n" + "一覧表示 -v" + "\n" + "ソート -s" + "\n" + "プログラム終了 -e");
|
224
|
-
|
225
|
-
s = sc.next();
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
if (s.equals("-s")) {
|
230
|
-
|
231
|
-
Object[] mapkey = memberMap.keySet().toArray();
|
232
|
-
|
233
|
-
Arrays.sort(mapkey);
|
234
|
-
|
235
|
-
}
|
236
|
-
|
237
|
-
if (s.equals("-e")) {
|
238
|
-
|
239
|
-
System.exit(0);
|
240
|
-
|
241
|
-
}
|
251
|
+
public class Member {
|
252
|
+
|
253
|
+
/**
|
254
|
+
|
255
|
+
* 名前、部署を設定します。
|
256
|
+
|
257
|
+
* @param name 名前
|
258
|
+
|
259
|
+
* @param department 部署
|
260
|
+
|
261
|
+
*/
|
262
|
+
|
263
|
+
private String name;
|
264
|
+
|
265
|
+
private String department;
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
public Member(String name, String department) {
|
270
|
+
|
271
|
+
this.name = name;
|
272
|
+
|
273
|
+
this.department = department;
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
public String getName() {
|
278
|
+
|
279
|
+
return name;
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
public String getDepartment() {
|
284
|
+
|
285
|
+
return department;
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
public void setName(String name) {
|
290
|
+
|
291
|
+
this.name = name;
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
public void setDepartment(String department) {
|
296
|
+
|
297
|
+
this.department = department;
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
public String toString() {
|
302
|
+
|
303
|
+
return "名前:" + this.getName() + " " + "部署:" + this.getDepartment();
|
242
304
|
|
243
305
|
}
|
244
306
|
|
@@ -247,71 +309,3 @@
|
|
247
309
|
|
248
310
|
|
249
311
|
```
|
250
|
-
|
251
|
-
```
|
252
|
-
|
253
|
-
package kadai18;
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
public class Member {
|
258
|
-
|
259
|
-
/**
|
260
|
-
|
261
|
-
* 名前、部署を設定します。
|
262
|
-
|
263
|
-
* @param name 名前
|
264
|
-
|
265
|
-
* @param department 部署
|
266
|
-
|
267
|
-
*/
|
268
|
-
|
269
|
-
private String name;
|
270
|
-
|
271
|
-
private String department;
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
public Member(String name, String department) {
|
276
|
-
|
277
|
-
this.name = name;
|
278
|
-
|
279
|
-
this.department = department;
|
280
|
-
|
281
|
-
}
|
282
|
-
|
283
|
-
public String getName() {
|
284
|
-
|
285
|
-
return name;
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
public String getDepartment() {
|
290
|
-
|
291
|
-
return department;
|
292
|
-
|
293
|
-
}
|
294
|
-
|
295
|
-
public void setName(String name) {
|
296
|
-
|
297
|
-
this.name = name;
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
|
-
public void setDepartment(String department) {
|
302
|
-
|
303
|
-
this.department = department;
|
304
|
-
|
305
|
-
}
|
306
|
-
|
307
|
-
public String toString() {
|
308
|
-
|
309
|
-
return "名前:" + this.getName() + " " + "部署:" + this.getDepartment();
|
310
|
-
|
311
|
-
}
|
312
|
-
|
313
|
-
}
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
```
|
1
恐れ入ります。<code>のなかに貼り付け致しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,6 +12,12 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
+
import java.util.Arrays;```
|
16
|
+
|
17
|
+
package kadai18;
|
18
|
+
|
19
|
+
|
20
|
+
|
15
21
|
import java.util.Arrays;
|
16
22
|
|
17
23
|
import java.util.HashMap;
|
@@ -240,7 +246,9 @@
|
|
240
246
|
|
241
247
|
|
242
248
|
|
243
|
-
|
249
|
+
```
|
250
|
+
|
251
|
+
```
|
244
252
|
|
245
253
|
package kadai18;
|
246
254
|
|
@@ -303,3 +311,7 @@
|
|
303
311
|
}
|
304
312
|
|
305
313
|
}
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
```
|