Repository navigation
coordinate Step4 complete #121
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4779357
step3 version_1 complete
foreverever 503b81b
step3 Rectangle Class corrected
foreverever 1bfaad4
step3 complete
foreverever 482a0c2
step4 complete
foreverever e0baf55
step4 final complete
foreverever dccac74
step4 feedback complete
foreverever 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
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 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
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,17 @@ | ||
| package domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class PointsFactory { | ||
| private static final int X_POSITION = 0; | ||
| private static final int Y_POSITION = 1; | ||
|
|
||
| public static List<Point> makePoints(List<Integer[]> positions) { | ||
| List<Point> pointList = new ArrayList<>(); | ||
| for (Integer[] position : positions) { | ||
| pointList.add(new Point(position[X_POSITION], position[Y_POSITION])); | ||
| } | ||
| return pointList; | ||
| } | ||
| } |
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,64 @@ | ||
| package domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class Rectangle { | ||
| private static final int ZERO = 0; | ||
| private static final int ONE = 1; | ||
| private static final int FOUR = 4; | ||
|
|
||
| private List<Point> points; | ||
|
|
||
| public Rectangle(List<Point> points) { | ||
|
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. points.size()가 4인지 체크해야 하지 않을까? |
||
| check(points); | ||
| this.points = points; | ||
| } | ||
|
|
||
| private void check(List<Point> points) { | ||
| checkSize(points); | ||
| int check = 0; | ||
| for (Point point : points) { | ||
| check += cntCoordinateValue(0, 0, point, points); | ||
| } | ||
| checkRectangle(check); | ||
| } | ||
|
|
||
| private void checkSize(List<Point> points) { | ||
| if (points.size() != 4) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
|
|
||
| private int cntCoordinateValue(int xCnt, int yCnt, Point point, List<Point> points) { | ||
| for (Point other : points) { | ||
| if (point.subtractXPoint(other) == ZERO) { | ||
| xCnt++; | ||
| } | ||
| if (point.subtractYPoint(other) == ZERO) { | ||
| yCnt++; | ||
| } | ||
| } | ||
| if (xCnt == 2 && yCnt == 2) { | ||
| return ONE; | ||
| } | ||
| return ZERO; | ||
| } | ||
|
|
||
| private void checkRectangle(int check) { | ||
| if (check == FOUR) { | ||
| return; | ||
| } | ||
| throw new IllegalArgumentException("사각형이 아닙니다"); | ||
| } | ||
|
|
||
| public int calculateArea() { | ||
| List<Double> length = new ArrayList<>(); | ||
| for (int i = 0; i < points.size() - 1; i++) { | ||
| length.add(points.get(i).calculateLength(points.get(i + 1))); | ||
| } | ||
| Collections.sort(length); | ||
| return (int) (length.get(ZERO) * length.get(ONE)); | ||
| } | ||
| } | ||
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,50 @@ | ||
| package domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Triangle { | ||
| private static final int ZERO = 0; | ||
| private static final int ONE = 1; | ||
| private static final int TWO = 2; | ||
|
|
||
| private List<Point> points; | ||
|
|
||
| public Triangle(List<Point> points) { | ||
|
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. points.size()가 3인지 체크해야 하지 않을까? |
||
| checkSize(points); | ||
| this.points = points; | ||
| } | ||
|
|
||
| private void checkSize(List<Point> points) { | ||
| if (points.size() != 3) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
|
|
||
| //삼각형 길이 구하기 | ||
| private List<Double> calculateTriangleLength() { | ||
| List<Double> lengths = new ArrayList<>(); | ||
| lengths.add(points.get(ZERO).calculateLength(points.get(ONE))); | ||
| lengths.add(points.get(ONE).calculateLength(points.get(TWO))); | ||
| lengths.add(points.get(ZERO).calculateLength(points.get(TWO))); | ||
| return lengths; | ||
| } | ||
|
|
||
| //헤론 공식 | ||
| private double findS(List<Double> lengths) { | ||
| double sum = 0; | ||
| for (int i = 0; i < points.size() - 1; i++) { | ||
| lengths.add(points.get(i).calculateLength(points.get(i + 1))); | ||
| sum += lengths.get(i); | ||
| } | ||
| lengths.add(points.get(ZERO).calculateLength(points.get(TWO))); | ||
| sum += lengths.get(TWO); | ||
| return (sum / 2); | ||
| } | ||
|
|
||
| public double calculateArea() { | ||
| List<Double> lengths = calculateTriangleLength(); | ||
| double s = findS(lengths); | ||
| return Math.sqrt(s * (s - lengths.get(ZERO)) * (s - lengths.get(ONE)) * (s - lengths.get(TWO))); | ||
| } | ||
| } | ||
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
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
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.
points.size()가 2인지 체크해야 하지 않을까?