Repository navigation
step2 pr합니다. #135
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합니다. #135
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,11 +1,31 @@ | ||
| package coordinates; | ||
|
|
||
| import coordinates.domain.Point; | ||
| import coordinates.util.MainControllerUtil; | ||
| import coordinates.view.InputView; | ||
| import coordinates.view.ResultView; | ||
| import org.slf4j.Logger; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.slf4j.LoggerFactory.getLogger; | ||
|
|
||
| public class MainController { | ||
| private static final int ZERO = 0; | ||
| private static final Logger log = getLogger(MainController.class); | ||
|
|
||
| private static CoordinatesServes coordinatesServes = new CoordinatesServes(); | ||
| private static MainControllerUtil mainControllerUtil = new MainControllerUtil(); | ||
|
|
||
| public static void main(String[] args) { | ||
| coordinatesServes.main(); | ||
| String inputPoint = InputView.pointInput(); | ||
| List<Integer> axiss = mainControllerUtil.axisNum(); | ||
| List<Integer> reversalAxis = mainControllerUtil.reversalAxisNum(); | ||
| List<Point> points = mainControllerUtil.objectCoordinates(inputPoint); | ||
|
|
||
| ResultView.graphWidthLin(points, reversalAxis, axiss); | ||
| System.out.print(String.format("%3d", ZERO)); | ||
| ResultView.height(axiss); | ||
|
|
||
| ResultView.mathLine(mainControllerUtil.getMathPoint(mainControllerUtil.objectLine(points))); | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
| package coordinates.domain; | ||
|
|
||
| public class Line { | ||
| private Point point; | ||
| private Point distinctPoint; | ||
|
|
||
| public Line(Point point, Point distinctPoint){ | ||
| this.point = point; | ||
| this.distinctPoint = distinctPoint; | ||
| } | ||
|
|
||
| public double mathPoint(){ | ||
| return point.getMath(distinctPoint); | ||
| } | ||
| } |
20 changes: 11 additions & 9 deletions
20
src/main/java/coordinates/Coordinates.java → src/main/java/coordinates/domain/Point.java
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,31 +1,33 @@ | ||
| package coordinates; | ||
| package coordinates.domain; | ||
|
|
||
| public class Coordinates { | ||
| public class Point { | ||
|
|
||
| private int x; | ||
| private int y; | ||
|
|
||
| public int getX() { | ||
| return x; | ||
| public Point(int x, int y){ | ||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
|
|
||
| public void setX(int x) { | ||
| this.x = x; | ||
| public int getX() { | ||
| return x; | ||
| } | ||
|
|
||
| public int getY() { | ||
| return y; | ||
| } | ||
|
|
||
| public void setY(int y) { | ||
| this.y = y; | ||
| public double getMath(Point point){ | ||
| return Math.sqrt(Math.pow(Math.abs(point.getX()-x),2)+Math.pow(Math.abs(point.getY()-y),2)); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Coordinates{" + | ||
| return "Point{" + | ||
| "x=" + x + | ||
| ", y=" + y + | ||
| '}'; | ||
| } | ||
|
|
||
| } |
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,58 @@ | ||
| package coordinates.util; | ||
|
|
||
| import coordinates.domain.Line; | ||
| import coordinates.domain.Point; | ||
| import org.slf4j.Logger; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import static org.slf4j.LoggerFactory.getLogger; | ||
|
|
||
| public class MainControllerUtil { | ||
| private static final int ZERO = 0; | ||
| private static final int ONE = 1; | ||
| private static final int TWO = 2; | ||
|
|
||
| private static final Logger log = getLogger(MainControllerUtil.class); | ||
|
|
||
| public List<Integer> axisNum() { | ||
| //List 1~24까지 숫자 넣기 | ||
| List<Integer> axis = new ArrayList<>(); | ||
| for (int i = 1; i <= 24; i++) { | ||
| axis.add(i); | ||
| } | ||
| return axis; | ||
| } | ||
|
|
||
| public List<Integer> reversalAxisNum() { | ||
| //List에 1~24를 24~1로 자리수 변환하기 | ||
| List<Integer> reversalAxis = axisNum(); | ||
| Collections.reverse(reversalAxis); | ||
|
|
||
| return reversalAxis; | ||
| } | ||
|
|
||
| public List<Integer> inputNumber(String input) { | ||
| //Scnner 입력값 객체 상속 받아 List로 변환 | ||
| return SplitUtil.changeNum(input); | ||
| } | ||
|
|
||
| public List<Point> objectCoordinates(String input) { | ||
| //point 객체 생성 | ||
| List<Point> coordinates = new ArrayList<>(); | ||
| for (int i = 0; i < inputNumber(input).size(); i = i + TWO) { | ||
| coordinates.add(new Point(inputNumber(input).get(i), inputNumber(input).get(i + ONE))); | ||
| } | ||
| return coordinates; | ||
| } | ||
|
|
||
| public Line objectLine(List<Point> points) { | ||
| return new Line(points.get(ZERO), points.get(ONE)); | ||
| } | ||
|
|
||
| public double getMathPoint(Line line) { | ||
| return line.mathPoint(); | ||
| } | ||
| } |
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,26 @@ | ||
| package coordinates.util; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class SplitUtil { | ||
|
|
||
| private static String input(String input){ | ||
| input = input.replace("(", "").replace(")","").replace("-",","); | ||
| return input; | ||
| } | ||
|
|
||
| private static String[] splitNum(String input){ | ||
| String[] split = input(input).split(","); | ||
| return split; | ||
| } | ||
|
|
||
| public static List<Integer> changeNum(String input){ | ||
| List<Integer> pointNum = new ArrayList<>(); | ||
|
|
||
| for (String number : splitNum(input)){ | ||
| pointNum.add(Integer.parseInt(number)); | ||
| } | ||
| return pointNum; | ||
| } | ||
| } | ||
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 coordinates.view; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class InputView { | ||
|
|
||
| private static Scanner s = new Scanner(System.in); | ||
|
|
||
| public static String pointInput(){ | ||
| 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 |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package coordinates.view; | ||
|
|
||
| import coordinates.domain.Point; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class ResultView { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메소드가 인스턴스 변수에 접근하지 않으면 굳이 인스턴스 메소드로 구현할 필요 없음 |
||
|
|
||
| private static final String STICK = "|"; | ||
| private static final String HORIZONTAL = " ̄"; | ||
| private static final String POINT = "ㆍ"; | ||
|
|
||
| public static void graphWidthLin(List<Point> points, List<Integer> reversalAxis, List<Integer> axis) { | ||
| for (int i = 0; i < 24; i++) { | ||
| System.out.print(String.format("%2d", reversalAxis.get(i))); | ||
| System.out.print(STICK); | ||
|
|
||
| twoLine(points, reversalAxis.get(i), axis); | ||
|
|
||
| System.out.println(); | ||
| } | ||
| } | ||
|
|
||
| private static void twoLine(List<Point> points, int reversalAxis, List<Integer> axis) { | ||
| for (int k = 0; k < 2; k++) { | ||
| if (points.get(k).getY() == reversalAxis) { | ||
| oneLine(points.get(k), axis); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void oneLine(Point points, List<Integer> axis) { | ||
| for (int j = 0; j < 24; j++) { | ||
| String blankNum = " "; | ||
| if (points.getX() == axis.get(j)) { | ||
| blankNum = POINT; | ||
| } | ||
| System.out.print(blankNum); | ||
| } | ||
| } | ||
|
|
||
| public static void graphHeightLine(int axis, boolean blank) { | ||
| String input = ""; | ||
| if (blank == true) { | ||
| input = String.valueOf(axis); | ||
| System.out.print(HORIZONTAL); | ||
| System.out.print(HORIZONTAL); | ||
| System.out.print(input); | ||
| } | ||
| } | ||
|
|
||
| public static void height(List<Integer> axiss) { | ||
| for (int i = 0; i < axiss.size(); i++) { | ||
| int axis = axiss.get(i); | ||
| graphHeightLine(axis, blankCondition(axiss.get(i))); | ||
| } | ||
| System.out.println(); | ||
| } | ||
|
|
||
| public static boolean blankCondition(int axis) { | ||
| //1~24까지의 %2는 true | ||
| return axis % 2 == 0; | ||
| } | ||
|
|
||
| public static void mathLine(double line) { | ||
| System.out.println("두 점의 길이는 : " + line); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
메소드가 인스턴스 변수에 접근하지 않으면 굳이 인스턴스 메소드로 구현할 필요 없음
클래스 메소드로 구현한다.