Repository navigation
Expand file tree
/
Copy pathResultView.java
More file actions
76 lines (67 loc) · 2.33 KB
/
Copy pathResultView.java
File metadata and controls
76 lines (67 loc) · 2.33 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
package view;
import domain.Line;
import domain.Point;
import domain.Rectangle;
import domain.Shape;
import java.util.ArrayList;
public class ResultView {
static final int MAX = 24;
public static void printPoints(ArrayList<Point> points) {
int pointIndex = 0;
for (int yIndex = MAX; yIndex >= 1; yIndex--) {
printYAxis(yIndex);
pointIndex = printPoint(points, pointIndex, yIndex);
System.out.println();
}
printXAxis();
}
private static int printPoint(ArrayList<Point> points, int pointIndex, int yIndex) {
for (int xIndex = 1; xIndex < MAX; xIndex++) {
if (points.size() <= pointIndex) {
continue;
}
Point point = points.get(pointIndex);
if (point.getY() != yIndex) {
return pointIndex;
}
pointIndex = printX(point, pointIndex, xIndex);
}
return pointIndex;
}
private static int printX(Point point, int pointIndex, int xIndex) {
if (point.getX() == xIndex) {
System.out.print(String.format("%2s", "●"));
return ++pointIndex;
}
System.out.print(String.format("%2s", " "));
return pointIndex;
}
private static Boolean printYAxis(int index) {
if (index % 2 == 0) {
System.out.print(String.format("%-2s" + "|", index));
return true;
}
System.out.print(String.format("%-2s" + "|", " "));
return false;
}
private static void printXAxis() {
System.out.print(" " + "+");
for (int i = 0; i < MAX; i++) {
System.out.print(String.format("%2s", "--")); // dash가 1개이면 x축이 짧아보여서 2개로 변경
}
System.out.print("\n" + String.format("%-3s", "0"));
for (int i = 1; i < 13; i++) {
System.out.print(String.format("%4s", i * 2));
}
}
public static void printCalculation(Shape shape) {
if (shape.hasLineCount(1)) {
Line line = (Line) shape;
System.out.println("\n두 점 사이 거리는 " + line.getDistance());
}
if (shape.hasLineCount(4)) {
Rectangle rectangle = (Rectangle) shape;
System.out.println("\n사각형의 넓이는 " + rectangle.getArea());
}
}
}