Repository navigation
Step3 구현 #102
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
Step3 구현 #102
Changes from all commits
Commits
Show all changes
2 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,25 +1,29 @@ | ||
| package coordinate; | ||
|
|
||
| import coordinate.domain.Coordinate; | ||
| import coordinate.domain.Line; | ||
| import coordinate.domain.Point; | ||
| import coordinate.dto.PointDtoFactory; | ||
| import coordinate.inputview.InputView; | ||
| import coordinate.resultview.ResultView; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| public class CoordinateMain { | ||
| public class CoordinateMain extends IllegalAccessException { | ||
| public static void main(String[] args) { | ||
| ArrayList<Point> points = InputView.input(); | ||
| ArrayList<Point> points; | ||
| try { | ||
| points = InputView.input(); | ||
| PointDtoFactory pointDtoFactory = new PointDtoFactory(points); | ||
|
|
||
| //dto 만들기 | ||
| PointDtoFactory pointDtoFactory = new PointDtoFactory(points); | ||
| Coordinate coordinate = new Coordinate(); | ||
| coordinate.drawPoint(pointDtoFactory.getPointDTO()); | ||
|
|
||
| Coordinate coordinate = new Coordinate(); | ||
| coordinate.drawPoint(pointDtoFactory.getPointDTO()); | ||
| ResultView resultView = new ResultView(coordinate.getCoordinatesAxis(), coordinate.getCoordinatePlane()); | ||
| resultView.toDo(points); | ||
|
|
||
| ResultView resultView = new ResultView(coordinate.getCoordinatesAxis(), coordinate.getCoordinatePlane()); | ||
| resultView.disPlay(Line.calculatorLine(points)); | ||
| } catch (IllegalArgumentException e) { | ||
| System.out.println(e.getMessage()); | ||
| main(args); | ||
| } | ||
| } | ||
| } |
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
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
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,46 @@ | ||
| package coordinate.domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
|
|
||
| public class Rectangle { | ||
| private ArrayList<Point> points; | ||
| private HashSet<Integer> base = new HashSet<>(); | ||
| private HashSet<Integer> height = new HashSet<>(); | ||
|
|
||
| public Rectangle(ArrayList<Point> points) { | ||
| this.points = points; | ||
| for (Point point : this.points) { | ||
| this.base.add(point.getXPoint()); | ||
| this.height.add(point.getYPoint()); | ||
| } | ||
| } | ||
|
|
||
| public String calculate() { | ||
| if (this.points.size() < 4) { | ||
| return "사각형이 아닙니다."; | ||
| } | ||
| if (isRectangle().equals(false)) { | ||
| throw new IllegalArgumentException("사각형이 아닙니다."); | ||
| } | ||
| int[] a = findBaseHeight(); | ||
| return "사각형의 면적은 " + (a[0] * a[1]) + " 입니다."; | ||
| } | ||
|
|
||
| private int[] findBaseHeight() { | ||
| int[] BaseAndHeight = new int[2]; | ||
| for (int i = 1; i < points.size(); i++) { | ||
| if (points.get(0).commpareXPoint(points.get(i)).equals(true)) { | ||
| BaseAndHeight[0] = points.get(0).subtractionYPoint(points.get(i)); | ||
| } | ||
| if (points.get(0).commpareYPoint(points.get(i)).equals(true)) { | ||
| BaseAndHeight[1] = points.get(0).subtractionXPoint(points.get(i)); | ||
| } | ||
| } | ||
| return BaseAndHeight; | ||
| } | ||
|
|
||
| private Boolean isRectangle() { | ||
| return (this.base.size() == 2 && this.height.size() == 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,11 +1,18 @@ | ||
| package coordinate.resultview; | ||
|
|
||
| import coordinate.domain.CoordinateYLine; | ||
| import coordinate.domain.Line; | ||
| import coordinate.domain.Point; | ||
| import coordinate.domain.Rectangle; | ||
| import coordinate.utils.CoordinateString; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
|
|
||
| public class ResultView { | ||
| private static final int FOUR = 4; | ||
| private static final int TWO = 2; | ||
|
|
||
| private static final int MAXiMUM_NUM = 24; | ||
| private static final String DASH = "---"; | ||
| private static final String PLUS = " +"; | ||
|
|
@@ -39,10 +46,12 @@ private void displayXCoordinate() { | |
| System.out.println(); | ||
| } | ||
|
|
||
| public void disPlay(double pointLine) { | ||
| displayYCoordinate(); | ||
| displayXCoordinate(); | ||
| System.out.println("두 점 사이 거리는 " + pointLine); | ||
| public void toDo(ArrayList<Point> points) { | ||
| HashMap<Integer, String> toDo = new HashMap<>(); | ||
| toDo.put(TWO, new Line(points).calculate()); | ||
| toDo.put(FOUR, new Rectangle(points).calculate()); | ||
|
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. 구현 잘 했네요. 👍 |
||
| displayTest(); | ||
| System.out.println(toDo.get(points.size())); | ||
| } | ||
|
|
||
| public void displayTest() { | ||
|
|
||
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
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.
return this.xPoint == point.xPoint;과 같이 구현 가능함.Y도 같음