Repository navigation
Step2 pr합니다. #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Step2 pr합니다. #128
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,27 @@ | ||
| package coordinate.controller; | ||
|
|
||
| import coordinate.domain.Movement; | ||
|
|
||
| import coordinate.view.InputView; | ||
| import coordinate.view.ResultView; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class CoordinateMain { | ||
|
|
||
| public static void main(String[] args) { | ||
| Movement m = new Movement(); | ||
|
|
||
| ResultView.height(m.axis()); | ||
| ResultView.width(m.axis()); | ||
| String temporaryPoint = InputView.inputPoint(); | ||
|
|
||
| List<Point> points = new ArrayList<>(m.pointCreate(temporaryPoint)); | ||
|
|
||
| List<Integer> x = new ArrayList<>(m.axis()); | ||
| List<Integer> y = new ArrayList<>(m.axis()); | ||
|
|
||
| ResultView.height(x, y, points); | ||
| ResultView.width(Movement.axis()); | ||
| ResultView.distance(points); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package coordinate.controller; | ||
|
|
||
| public class Point { | ||
| private int x = 0; | ||
| private int y = 0; | ||
|
|
||
| public Point(int x, int y) { | ||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
|
|
||
| public int getX() { | ||
| return x; | ||
| } | ||
|
|
||
| public int getY() { | ||
| return y; | ||
| } | ||
|
|
||
| public double getDistance(Point point){ | ||
| //제곱근((A.x - B.x)^제곱 + (A.y - B.y)^제곱) | ||
| return Math.sqrt(Math.pow(Math.abs(x - point.getX()),2)+Math.pow(Math.abs(y-point.getY()),2)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,50 @@ | ||
| package coordinate.domain; | ||
|
|
||
| import coordinate.controller.Point; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| public class Movement { | ||
|
|
||
| private static final int MAX_NUM = 24; | ||
|
|
||
| public ArrayList<Integer> axis() { | ||
| ArrayList<Integer> axisNum = new ArrayList<>(); | ||
| public static List<Integer> axis() { | ||
| List<Integer> axisNum = new ArrayList<>(); | ||
| for (int i = 0; i <= MAX_NUM; i++) { | ||
| axisNum.add(i); | ||
| } | ||
| return axisNum; | ||
| } | ||
| } | ||
|
|
||
| public List<Point> pointCreate(String temporaryPoint) { | ||
| return pointObject(cutPoint(conversion(temporaryPoint))); | ||
| } | ||
|
|
||
| private String conversion(String temporaryPoint) { | ||
| String input = temporaryPoint. | ||
| replace("(", ""). | ||
| replace(")", ""). | ||
| replace("-", ","); | ||
| return input; | ||
| } | ||
|
|
||
| private int[] cutPoint(String temporaryPoint) { | ||
| String[] point = temporaryPoint.split(","); | ||
| // String a = "1"; | ||
| // int b = Integer.parseInt(a); | ||
| int[] input = Arrays.asList(point).stream().mapToInt(Integer::parseInt).toArray(); | ||
|
|
||
| return input; | ||
| } | ||
|
|
||
| private List<Point> pointObject(int[] temporaryPoint) { | ||
| List<Point> points = new ArrayList<>(); | ||
|
|
||
| for (int i = 0; i < temporaryPoint.length; i = i + 2) { | ||
| points.add(new Point(temporaryPoint[i], temporaryPoint[i + 1])); | ||
| } | ||
| return points; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package coordinate.view; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class InputView { | ||
|
|
||
| public static String inputPoint() { | ||
| Scanner s = new Scanner(System.in); | ||
|
|
||
| System.out.println("좌표를 입력하세요."); | ||
| return s.next(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,50 +1,83 @@ | ||
| package coordinate.view; | ||
|
|
||
| import java.util.ArrayList; | ||
| import coordinate.controller.Point; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class ResultView { | ||
|
|
||
| private static final String WIDTH_LINE = "│"; | ||
| private static final String BLANK = " "; | ||
| private static final String HEIGHT_LINE = "─"; | ||
| private static final String POINT = "ㆍ"; | ||
|
|
||
| private static String input = ""; | ||
|
|
||
| public static void height(List<Integer> y, List<Integer> x, List<Point> points) { | ||
| Collections.reverse(y); | ||
|
|
||
| static String input = ""; | ||
| for (int i = 0; i < y.size() - 1; i++) { | ||
| input = String.format("%2s", BLANK); | ||
| input = multiple(y.get(i), input); | ||
| System.out.print(input); | ||
| System.out.print(WIDTH_LINE); | ||
|
|
||
| public static void width(ArrayList<Integer> axisNum) { | ||
| pointDisplay(y.get(i), x, points); | ||
| System.out.println(); | ||
| } | ||
| } | ||
|
|
||
| private static String multiple(int axisNum, String input) { | ||
| if (axisNum % 2 == 0) { | ||
| input = String.format("%2d", axisNum); | ||
| } | ||
| return input; | ||
| } | ||
|
|
||
| private static void pointDisplay(int y, List<Integer> x, List<Point> point) { | ||
| for (int j = 1; j < x.size(); j++) { | ||
| input = BLANK; | ||
| pointRepetition(y, point, j); | ||
| System.out.print(input); | ||
| } | ||
| } | ||
|
|
||
| private static void pointRepetition(int y, List<Point> point, int coordinatesX) { | ||
| for (int k = 0; k < point.size(); k++) { | ||
| locationCriteria(y, point.get(k).getX(), point.get(k).getY(), coordinatesX); | ||
| } | ||
| } | ||
|
|
||
| private static void locationCriteria(int line, int pointX, int pointY, int coordinatesX) { | ||
| if (condition(pointX, coordinatesX) && condition(pointY, line)) { | ||
| input = POINT; | ||
| } | ||
| } | ||
|
|
||
| private static boolean condition(int point, int index) { | ||
| return point == index; | ||
| } | ||
|
|
||
| public static void width(List<Integer> axisNum) { | ||
| System.out.print(String.format("%3s", "+")); | ||
| for (int i = 0; i < axisNum.size(); i++) { | ||
| System.out.print(HEIGHT_LINE); | ||
| } | ||
| System.out.println(); | ||
|
|
||
| widthNum(axisNum); | ||
| System.out.println(); | ||
| } | ||
|
|
||
| private static void widthNum(ArrayList<Integer> axisNum) { | ||
| private static void widthNum(List<Integer> axisNum) { | ||
| for (Integer integer : axisNum) { | ||
| input = String.format("%2s", BLANK); | ||
| input = multiple(integer, input); | ||
| System.out.print(input); | ||
| } | ||
| } | ||
|
|
||
| public static void height(ArrayList<Integer> axisNum) { | ||
| Collections.reverse(axisNum); | ||
|
|
||
| for (int i = 0; i < axisNum.size() - 1; i++) { | ||
| input = String.format("%2s", BLANK); | ||
| input = multiple(axisNum.get(i), input); | ||
| System.out.print(input); | ||
| System.out.println(WIDTH_LINE); | ||
| } | ||
| } | ||
|
|
||
| private static String multiple(int axisNum, String input) { | ||
| if (axisNum % 2 == 0) { | ||
| input = String.format("%2d", axisNum); | ||
| } | ||
|
|
||
| return input; | ||
| public static void distance(List<Point> points) { | ||
| System.out.println("두 점 사이 거리는 : " + points.get(0).getDistance(points.get(1))); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input을 전역 변수로 두고 구현하기 보다 로컬 변수로 구현해본다.