Repository navigation
Expand file tree
/
Copy pathChapter02.java
More file actions
158 lines (129 loc) · 3.53 KB
/
Copy pathChapter02.java
File metadata and controls
158 lines (129 loc) · 3.53 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import ch02.ex13.OsCpu;
import ch02.ex17.Queue;
import com.opencsv.bean.CsvToBeanBuilder;
import org.junit.Test;
import org.omg.CORBA.IntHolder;
import java.io.FileReader;
import java.io.IOException;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
public class Chapter02 {
@Test
public void ex01() {
LocalDate date = LocalDate.now().withDayOfMonth(1);
int month = date.getMonthValue();
System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
DayOfWeek weekday = date.getDayOfWeek();
int value = convertWeek(weekday.getValue());
for (int i = 1; i < value; i++) {
System.out.print(" ");
}
while (date.getMonthValue() == month) {
System.out.printf("%4d", date.getDayOfMonth());
date = date.plusDays(1);
if (convertWeek(date.getDayOfWeek().getValue()) == 1) {
System.out.println();
}
}
}
/**
* 요일 번호를 월요일(1)~일요일(7)에서 일요일(1)~토요일(7)으로 변경한다.
*
* @param value 요일 번호. 월요일(1) ~ 일요일(7)
* @return 요일 번호. 일요일(1) ~ 토요일(7)
*/
private int convertWeek(int value) {
// 7 -> 1
// 1 -> 2
// 2 -> 3
// 3 -> 4
// 4 -> 5
// 5 -> 6
// 6 -> 7
return value + 1 > 7 ? 1 : value + 1;
}
@Test
public void ex02() {
try (Scanner scanner = new Scanner(System.in);) {
int nextInt = scanner.nextInt();
System.out.println(nextInt);
}
Random r = new Random();
r.nextInt(20);
}
@Test
public void ex04() {
IntHolder ih1 = new IntHolder(10);
IntHolder ih2 = new IntHolder(20);
System.out.println("ih1 = " + ih1.value + ", ih2 = " + ih2.value);
// 교체
int temp = ih1.value;
ih1.value = ih2.value;
ih2.value = temp;
System.out.println("ih1 = " + ih1.value + ", ih2 = " + ih2.value);
Integer i1 = new Integer(111);
Integer i2 = new Integer(222);
System.out.println("i1 = " + i1 + ", i2 = " + i2);
Integer t = i1;
i1 = i2;
i2 = t;
System.out.println("i1 = " + i1 + ", i2 = " + i2);
}
@Test
public void ex05() {
ch02.ex05.Point p = new ch02.ex05.Point(3, 4).translate(1, 3).scale(0.5);
System.out.println(p.getX());
System.out.println(p.getY());
}
@Test
public void ex06() {
ch02.ex06.Point p = new ch02.ex06.Point(3, 4).translate(1, 3).scale(0.5);
System.out.println(p.getX());
System.out.println(p.getY());
}
@Test
public void ex10() {
// ch02.ex10.RandomNumbers
// ch02.ex10.MyArrayList
}
@Test
public void ex11() {
// ch02.ex11.Cal
}
@Test
public void ex13() throws IOException {
FileReader reader = new FileReader("docs/ch02/dump.csv");
List<OsCpu> beans = new CsvToBeanBuilder<OsCpu>(reader).withType(OsCpu.class).build().parse();
for (OsCpu bean : beans) {
System.out.println(bean);
}
}
@Test
public void ex16() {
ch02.ex16.Queue q = new ch02.ex16.Queue();
q.add(new ch02.ex16.Queue.Node("a"));
q.add(new ch02.ex16.Queue.Node("n"));
q.add(new ch02.ex16.Queue.Node("t"));
q.add(new ch02.ex16.Queue.Node("o"));
q.add(new ch02.ex16.Queue.Node("p"));
ch02.ex16.Queue.Node node = q.remove();
System.out.println("removed node. " + node);
}
@Test
public void ex17() {
ch02.ex17.Queue q = new ch02.ex17.Queue();
q.add(new ch02.ex17.Queue.Node("a"));
q.add(new ch02.ex17.Queue.Node("n"));
q.add(new ch02.ex17.Queue.Node("t"));
q.add(new ch02.ex17.Queue.Node("o"));
q.add(new ch02.ex17.Queue.Node("p"));
Queue.Iterator iterator = q.getIterator();
while (iterator.hasNext()) {
ch02.ex17.Queue.Node node = iterator.next();
System.out.println(node);
}
}
}