Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repositories {
}

dependencies {
testImplementation 'org.assertj:assertj-core:3.11.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
Expand Down
60 changes: 60 additions & 0 deletions markdown_practice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!-- Heading -->
# Heading 1
___
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6
Paragraph

<!-- Text attributes -->
This is the **bold** text and this is the *italic* text and let's
do ~~strikethrough~~.

<!-- Quote -->
>Don't forget to code your dream.

<!-- Bullet List -->
Fruits
* Apple
* Banana

Players
- kane
- son

<!-- Numbered list -->
Numbers
1. first
2. second
3. third

<!-- Link -->
CLick [wapago's github](https://github.com/wapago)

<!-- Image -->

![이미지 설명](https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F233CB1385745B3CC14)

<!-- Table -->
| Header | Description |
|-------:|-------------:|
| cell1 | cell2 |
|cell3|cell4|

<!-- Code -->
To print message in the console, use
`console.log('your message')` and ...
```java
public class Example {
public static void main(String[] args) {
console.log('your messages');
}
}
```





59 changes: 59 additions & 0 deletions src/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# *좌표계산기(선 길이)*
___
### 기능 요구사항
- 사용자가 점에 대한 좌표 정보를 입력하는 메뉴를 구성한다.
- 좌표정보는 괄호(",")로 둘러쌓여 있으며 쉼표(,)로 x값과 y값을 구분한다.
- x , y 좌표 모두 최대 24까지만 입력할 수 있다.
- 입력 범위를 초과할 경우 에러 문구를 출력하고 다시 입력을 받는다.
- 정상적인 좌표값을 입력한 경우, 해당 좌표에 특수문자를 표시한다.
- 좌표값을 두 개 입력한 경우, 두 점을 잇는 직선으로 가정한다. 좌표값과 좌표값 사이는 '-' 문자로 구분한다.
- 직선인 경우는 두 점 사이 거리를 계산해서 출력한다.

### 실행결과
```java
좌표를 입력하세요.
(10,10)-(14,15)
```

### 힌트
- 두 점 사이 거리는 제곱근((A.x - B.x)^제곱 + (A.y - B.y)^제곱)공식으로 계산할 수 있다.
- 제곱근을 구하는 수학 함수는 Math.sqrt()를 활용한다.
- 테스트 코드의 경우 double일 때 근사치를 테스트하는 경우가 많다.
### 테스트 assert 힌트
- junit은 `assertEquals(1.414, line.length(), 0.001);` 과 같이 세번째 인자에 정밀도를 지정할 수 있다.
- assertj는 `assertThat(line.length()).isEqualTo(1.414, offset(o.00099));` 과 같이 offset 메소드르 정밀도를 지정할 수 있다.

# *좌표계산기(사각형 면적)*
___
### 기능 요구사항
- 좌표값을 두 개 입력한 경우, 두 점을 잇는 직선으로 가정한다. 좌표값과 좌표값 사이는 '-'문자로 구분한다.
- 좌표값을 네 개 입력한 경우, 네 점을 연결하는 사각형으로 가정한다.
- 네 점이 뒤틀어진 사다리꼴이나 마름모는 제외하고 직사각형만 허용하도록 검사한다.
- 사각형인 경우 사각형의 넓이를 계산해서 출력한다.

### 실행결과
```java
좌표를 입력하세요.
(10,10)-(22,10)-(22,18)-(10,18)
```

### 힌트
- 사각형 면적은 width * height 방식으로 계산할 수 있다.
- Point라는 객체를 추가해 x,y좌표를 관리하도록 한다.


# *좌표계산기(삼각형 면적)*
___
### 기능 요구사항
- 좌표값을 두 개 입력한 경우, 두 점을 잇는 직선으로 가정한다. 좌표값과 좌표값 사이는 '-'문자로 구분한다.
- 좌표값을 세 개 입력한 경우, 세 점을 연결하는 삼각형으로 가정한다.
- 삼각형인 경우 삼각형의 넓이를 계산해서 출력한다.

### 실행결과
```java
좌표를 입력하세요.
(10,10)-(14,15)-(20,8)
```

### 힌트
- 세 변의 길이를 알 때 삼각형의 넓이를 구하는 공식은 헤론의 공식을 이용해 구할 수 있다.
7 changes: 7 additions & 0 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import coordinate.CoordinateCalculator;

public class Main {
public static void main(String[] args) {
new CoordinateCalculator().start();
}
}
21 changes: 21 additions & 0 deletions src/main/java/coffee/CaffeineBeverage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package coffee;

public abstract class CaffeineBeverage {
abstract void brew();
abstract void addCondiments();

void prepareRecipe() {
boilWater();
brew();
pourInCup();
addCondiments();
}

public void boilWater() {
System.out.println("물을 끓인다.");
}

public void pourInCup() {
System.out.println("컵에 붓는다.");
}
}
14 changes: 14 additions & 0 deletions src/main/java/coffee/Coffee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package coffee;

public class Coffee extends CaffeineBeverage {

@Override
void brew() {
System.out.println("필터를 활용해 커피를 내린다.");
}

@Override
void addCondiments() {
System.out.println("설탕과 우유를 추가한다.");
}
}
14 changes: 14 additions & 0 deletions src/main/java/coffee/Tea.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package coffee;

public class Tea extends CaffeineBeverage{

@Override
void brew() {
System.out.println("티백을 담근다.");
}

@Override
void addCondiments() {
System.out.println("레몬을 추가한다.");
}
}
28 changes: 28 additions & 0 deletions src/main/java/coordinate/CoordinateCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package coordinate;

import coordinate.calculatorview.InputView;
//import coordinate.factory.CalculationFactory;
import coordinate.factory.CalculationFactory;
import coordinate.factory.PolygonFactory;
import coordinate.shape.Polygon;

public class CoordinateCalculator {
private Points points;

public void start() {
init();
Polygon polygon = PolygonFactory.getPolygonType(this.points);
double result = CalculationFactory.calculate(polygon);

System.out.println("result = " + result);
}

public void init() {
InputView.askPoints();
initPoints(InputView.getPoints());
}

public void initPoints(String points) {
this.points = new Points(points);
}
}
52 changes: 52 additions & 0 deletions src/main/java/coordinate/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package coordinate;

import java.util.ArrayList;
import java.util.List;

public class Point {

private final List<String[]> strPointList = new ArrayList<>();
private final int[] pointArray = new int[2];

private final List<int[]> pointList = new ArrayList<>();

private int x;
private int y;

public Point(String points) {
pointsToList(points);
parseStrPointList(this.strPointList);
setPoint(pointList);
}

public void pointsToList(String points) {
strPointList.add(points.split(","));
}

public void parseStrPointList(List<String[]> strPointList) {
for (String[] point : strPointList) {
pointArray[0] = Integer.parseInt(point[0]);
pointArray[1] = Integer.parseInt(point[1]);

pointList.add(pointArray);
}
}

public void setPoint(List<int[]> pointList) {
for (int[] point : pointList) {
this.x = point[0];
this.y = point[1];
}
}

public int getX() {
return x;
}

public int getY() {
return y;
}



}
47 changes: 47 additions & 0 deletions src/main/java/coordinate/Points.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package coordinate;

import java.util.*;

public class Points {

private final List<Point> points;
private final int length;

public Points(String points) {
String[] splitPoints = splitPointsInput(points);

this.length = splitPoints.length;
this.points = makePoints(splitPoints);
}

public List<Point> getPoints() {
return points;
}

public int getLength() {
return length;
}

public String[] splitPointsInput(String points) {
points = points.replace("(","").replace(")","");

return points.split("-");
}

public List<Point> makePoints(String[] splitPoints) {
return Arrays.stream(splitPoints).map(Point::new).toList();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Points points1 = (Points) o;
return length == points1.length && Objects.equals(points, points1.points);
}

@Override
public int hashCode() {
return Objects.hash(points, length);
}
}
30 changes: 30 additions & 0 deletions src/main/java/coordinate/calculatorview/InputView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package coordinate.calculatorview;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class InputView {
private static final Scanner SCANNER = new Scanner(System.in);
private static final String NATURAL_NUMBER = "[0-9][0-9]*";
private static final String POINT = "\\((" + NATURAL_NUMBER + "," + NATURAL_NUMBER + ")\\)";
private static final Pattern POINTS_PATTERN = Pattern.compile(POINT + "(?:-" + POINT + "){1,3}");

public static void askPoints() {
System.out.println("좌표를 입력하세요");
}

public static String getPoints() {
try {
String input = SCANNER.nextLine();
Matcher matcher = POINTS_PATTERN.matcher(input);
if (!matcher.find()) {
throw new IllegalArgumentException("좌표 입력 형식이 맞지 않습니다.");
}

return input;
} catch(IllegalArgumentException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
}
8 changes: 8 additions & 0 deletions src/main/java/coordinate/domain/Calculatable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package coordinate.domain;


public interface Calculatable {
double calculateArea();

String getPolygonName();
}
Loading