-
Notifications
You must be signed in to change notification settings - Fork 248
/
Copy pathImageReSolution.java
50 lines (39 loc) · 1.12 KB
/
ImageReSolution.java
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
package nextstep.session.domain;
public class ImageReSolution {
private static final int WIDTH_RATIO = 3;
private static final int HEIGHT_RATIO = 2;
private final int width;
private final int height;
public ImageReSolution(int width, int height) {
validateImageDimensions(width, height);
this.width = width;
this.height = height;
}
private void validateImageDimensions(int width, int height) {
if (width <= 0 || height <= 0) {
throw new IllegalArgumentException("가로와 세로 길이는 양의 정수여야 합니다.");
}
if (width < 300 || height < 200) {
throw new IllegalArgumentException("가로는 300 이상, 세로는 200 이상이어야 합니다.");
}
if (isValidRatio(width) != height) {
throw new IllegalArgumentException("가로세로비율이 3:2가 아닙니다.");
}
}
private int isValidRatio(int width) {
return width / WIDTH_RATIO * HEIGHT_RATIO;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
@Override
public String toString() {
return "ImageReSolution{" +
"width=" + width +
", height=" + height +
'}';
}
}