Repository navigation
submit step5 1st #116
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
submit step5 1st #116
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 |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package coordinate; | ||
|
|
||
| import coordinate.factory.*; | ||
| import java.util.*; | ||
|
|
||
| public class Coordinate { | ||
| private List<Point> points = new ArrayList<>(); | ||
|
|
||
| public Coordinate(List<Integer> numbers) throws IllegalArgumentException { | ||
| for (int i = 0; i < numbers.size(); i++) { | ||
| if (i % 2 == 0) | ||
| points.add(new Point(numbers.get(i), numbers.get(i + 1))); | ||
| } | ||
| mismatchPointCount(); | ||
| checkSameDot(); | ||
| } | ||
|
|
||
| public String createFigure() throws IllegalArgumentException { | ||
| HashMap<Integer, FigureFactory> map = new HashMap<>(); | ||
| map.put(2, new LineFactory()); | ||
| map.put(3, new TriangleFactory()); | ||
| map.put(4, new RectangleFactory()); | ||
| return map.get(points.size()).create(points).outputMessage(); | ||
| } | ||
|
|
||
| public void mismatchPointCount() { | ||
| if (points.size() < 2 || points.size() > 4) | ||
| throw new IllegalArgumentException("점의 개수는 2개혹은 3개 또는 4개 이어야 합니다."); | ||
| } | ||
|
|
||
| public void checkSameDot() throws IllegalArgumentException { | ||
| for (int i = 0; i < points.size(); i++) { | ||
| if (subCheckSameDot(i)) | ||
| throw new IllegalArgumentException("위치가 같은 점(point)이 존재합니다. " + points.size() + " 개점의 위치는 달라야 합니다."); | ||
| } | ||
| } | ||
|
|
||
| private Boolean subCheckSameDot(int i) { | ||
| for (int j = i + 1; j < points.size(); j++) { | ||
| if (points.get(i).equals(points.get(j))) | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public List<Point> getPoints() { | ||
| return 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
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 |
|---|---|---|
| @@ -1,21 +1,45 @@ | ||
| package coordinate; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class Point { | ||
| private int x; | ||
| private int y; | ||
|
|
||
| public Point(int x, int y) throws IllegalArgumentException { | ||
| if (x < 0 || x > 24 || y < 0 || y > 24) | ||
| throw new IllegalArgumentException(); | ||
| throw new IllegalArgumentException("x와 y값은 0초과 24미만 값이어야 합니다."); | ||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
|
|
||
| public double calculatorLength(Point points) { | ||
| return Math.sqrt(Math.pow(this.x - points.x, 2) + Math.pow(this.y - points.y, 2)); | ||
| public double calculatorLength(Point point) { | ||
| return Math.sqrt(Math.pow(this.x - point.x, 2) + Math.pow(this.y - point.y, 2)); | ||
| } | ||
|
|
||
| public Boolean matchX(Point point) { | ||
| return this.x == point.x; | ||
| } | ||
|
|
||
| public Boolean matchY(Point point) { | ||
| return this.y == point.y; | ||
| } | ||
|
|
||
| public Boolean matchDot(int x, int y) { | ||
| return this.x * 3 == x && this.y == y; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (!(o instanceof Point)) return false; | ||
| Point point = (Point) o; | ||
| return x == point.x && | ||
| y == point.y; | ||
| } | ||
|
|
||
| public Boolean matchPoint(int x, int y) { | ||
| return this.x*3 == x && this.y == y; | ||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(x, 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
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,10 @@ | ||
| package coordinate.factory; | ||
|
|
||
| import coordinate.Point; | ||
| import coordinate.figure.Figure; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface FigureFactory { | ||
| Figure create(List<Point> 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,14 @@ | ||
| package coordinate.factory; | ||
|
|
||
| import coordinate.Point; | ||
| import coordinate.figure.Figure; | ||
| import coordinate.figure.Line; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class LineFactory implements FigureFactory { | ||
| @Override | ||
| public Figure create(List<Point> points) { | ||
| return new Line(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,14 @@ | ||
| package coordinate.factory; | ||
|
|
||
| import coordinate.Point; | ||
| import coordinate.figure.Figure; | ||
| import coordinate.figure.Rectangle; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class RectangleFactory implements FigureFactory { | ||
| @Override | ||
| public Figure create(List<Point> points) { | ||
| return new Rectangle(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,14 @@ | ||
| package coordinate.factory; | ||
|
|
||
| import coordinate.Point; | ||
| import coordinate.figure.Figure; | ||
| import coordinate.figure.Triangle; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class TriangleFactory implements FigureFactory { | ||
| @Override | ||
| public Figure create(List<Point> points) { | ||
| return new Triangle(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,25 @@ | ||
| package coordinate.figure; | ||
|
|
||
| import coordinate.Point; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| public abstract class Figure implements FigureMessage , FigureProperty{ | ||
| private List<Point> points; | ||
|
|
||
| public Figure(List<Point> points) { | ||
| this.points = points; | ||
| } | ||
|
|
||
| protected List<Double> eachLengthFromFirstPoint() { | ||
| List<Double> lengths = new ArrayList<>(); | ||
| for (int i = 1; i < points.size(); ++i) { | ||
| lengths.add(points.get(0).calculatorLength(points.get(i))); | ||
| } | ||
| return lengths; | ||
| } | ||
|
|
||
| protected Point getPoints(int index) { | ||
| return points.get(index); | ||
| } | ||
| } | ||
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,5 @@ | ||
| package coordinate.figure; | ||
|
|
||
| public interface FigureMessage { | ||
| String outputMessage(); | ||
| } |
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,6 @@ | ||
| package coordinate.figure; | ||
|
|
||
| public interface FigureProperty { | ||
| double area(); | ||
| String name(); | ||
| } |
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.
이와 같이 전체 데이터를 공개하기 보다 다음과 같은 메소드면 충분하지 않을까?
접근 제어자도 꼭 필요한 범위로 한정하도록 한다.