-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from jbw9964:main
`자바의 신 3 판 VOL.1 기초 문법편` 공부 완료
- Loading branch information
Showing
39 changed files
with
3,682 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 @@ | ||
|
||
### <자바의 신> 중간 점검 및 실습 | ||
|
||
- [`1. 요약 문제`](./overview_problems/README.md) | ||
- [`2. 실습 문제`](./overview_problems/README.md) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 @@ | ||
|
||
### <자바의 신> 중간 점검 및 실습 - 실습 문제 | ||
|
||
- `[1]` : `CalculateSalary` 라는 클래스를 `c.middle` 이라는 패키지에 만들자. | ||
- `[2]` : `[1]` 에서 만든 클래스가 샐행될 수 있도록 `main()` 메서드를 추가하자. | ||
- `[3]` : 각 직원의 타입과 연봉을 저장하는 `Employee` 라는 클래스를 만들자. 이 클래스에는 `String` 타입의 `name` `(이름)`, `int` 타입의 `type` `(업무 역할)`, `long` 타입의 `salary` `(연봉)` 가 `private` 로 선언되어야 한다. | ||
- `[4]` : `Employee` 클래스의 각 변수 값을 지정하는 `setName()`, `setType()`, `setSalary()` 메서드와 조회하는 `getName()`, `getType()`, `getSalary()` 메서드를 만들어 내용을 채워 넣자. | ||
- `[5]` : `Employee` 클래스의 객체 생성시 모든 값을 한번에 지정할 수 있는 생성자를 만들자. 메서드 선언은 다음과 같다. | ||
|
||
```java | ||
public Employee(String name, int type, long salary); | ||
``` | ||
|
||
`public long getSalaryIncrease(Employee employee)` 라는 메서드를 `CalculateSalary` 클래스에 추가하자. | ||
|
||
- `[6]` : `Employee` 객체에 선언되어 있는 `type` 값에 따른 연봉 인상율은 다음과 같다. | ||
|
||
|`Type`|`Value`|`Increase Ratio`| | ||
|:---:|:---:|:---:| | ||
|`owner`|`1`| `-95%`| | ||
|`manager`|`2`| `10%`| | ||
|`designer`|`3`| `20%`| | ||
|`architect`|`4`| `30%`| | ||
|`developer`|`5`| `100%`| | ||
|
||
이 데이터를 이용하여 `Employee` 객체가 들어오면 인상된 연봉을 리턴해 주도록 `getSalaryIncrease()` 메서드를 채우자. | ||
|
||
- `[7]` : `public void calculateSalaries()` 라는 메서드를 `CalculateSalary` 클래스에 추가하자. `calculateSalaries()` 메서드에 다음 5 개 값을 갖는 `Employee` 배열을 만들자. | ||
|
||
|`name`|`type`|`salary`| | ||
|:---:|:---:|---:| | ||
|`LeeDaeRi`|`1`| `1_000_000_000`| | ||
|`KimManager`|`2`| `100_000_000`| | ||
|`WhangDesign`|`3`| `70_000_000`| | ||
|`ParkArchi`|`4`| `80_000_000`| | ||
|`LeeDevelop`|`5`| `60_000_000`| | ||
|
||
- `[8]` : `calculateSalaries()` 메서드에서 `for` 루프를 이용하여 `9` 에서 생성한 `Employee` 배열의 각 값을 꺼내어 연봉을 계산하고, 그 결과를 `"이름 = 계산된 연봉금액"` 형식으로 출력하도록 하자. `CalculateSalary` 의 `main()` 메서드에서 `calculateSalaries()` 메서드를 호출하여 결과를 확인해 보자. | ||
|
||
``` | ||
LeeDaeRi = 50,000,000 | ||
KimManager = 110,000,000 | ||
WhangDesign = 84,000,000 | ||
ParArchi = 104,000,000 | ||
LeeDevelop = 120,000_000 | ||
``` |
71 changes: 71 additions & 0 deletions
71
scripts/GOJ_mid_check/practice_problems/code/CalculateSalary.java
This file contains 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,71 @@ | ||
package scripts.GOJ_mid_check.practice_problems.code; | ||
|
||
import Practice.TestAnnotation; | ||
import scripts.GOJ_mid_check.practice_problems.code.Employee; | ||
|
||
@SuppressWarnings("unused") | ||
public class CalculateSalary { | ||
|
||
public static final String[] testNameArray = { | ||
"LeeDaeRi", | ||
"KimManager", | ||
"WhangDesign", | ||
"ParkArchi", | ||
"LeeDevelop" | ||
}; | ||
public static final Employee.Type[] testTypeArray = { | ||
Employee.Type.OWNER, | ||
Employee.Type.MANAGER, | ||
Employee.Type.DESIGNER, | ||
Employee.Type.ARCHITECT, | ||
Employee.Type.DEVELOPER | ||
}; | ||
public static final long[] testSalaryArray = { | ||
1_000_000_000, | ||
100_000_000, | ||
70_000_000, | ||
80_000_000, | ||
60_000_000 | ||
}; | ||
|
||
|
||
public static void main(String[] args) throws Exception { | ||
if (testNameArray.length != testTypeArray.length | ||
|| testTypeArray.length != testSalaryArray.length) { | ||
throw new Exception( | ||
"Static fields for test should have same lengths : (" + | ||
testNameArray.length + ", " + testTypeArray.length + ", " + testSalaryArray.length + | ||
")" | ||
); | ||
} | ||
|
||
|
||
int length = testNameArray.length; | ||
|
||
for (int i = 0; i < length; i++) { | ||
String name = testNameArray[i]; | ||
Employee.Type type = testTypeArray[i]; | ||
long salary = testSalaryArray[i]; | ||
|
||
Employee testEmployee = new Employee(name, type, salary); | ||
salary = getSalaryIncrease(testEmployee); | ||
|
||
System.out.printf( | ||
"%-10s\t= %,15d\n", | ||
name, salary | ||
); | ||
} | ||
} | ||
|
||
public static long getSalaryIncrease(Employee employee) throws NullPointerException { | ||
if (employee == null) throw new NullPointerException("Parameter 'Employee employee' has null reference"); | ||
|
||
long salary = employee.getSalary(); | ||
double ratio = employee.getType().getRatio(); | ||
|
||
salary = (long) (salary + ratio * salary); | ||
|
||
return salary; | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
scripts/GOJ_mid_check/practice_problems/code/Employee.java
This file contains 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,65 @@ | ||
package scripts.GOJ_mid_check.practice_problems.code; | ||
|
||
public class Employee { | ||
public enum Type { | ||
OWNER(1), MANAGER(2), DESIGNER(3), ARCHITECT(4), DEVELOPER(5); | ||
|
||
private int type; | ||
private Type(int type) {this.type = type;} | ||
|
||
public int getType() {return type;} | ||
public double getRatio() throws RuntimeException { | ||
double ratio; | ||
|
||
switch (this.type) { | ||
case 1 : ratio = -0.95d; break; | ||
case 2 : ratio = 0.1d; break; | ||
case 3 : ratio = 0.2d; break; | ||
case 4 : ratio = 0.3d; break; | ||
case 5 : ratio = 1.0d; break; | ||
|
||
default : throw new RuntimeException( | ||
"Unexpected type encountered in Employee.Type constant" | ||
); | ||
} | ||
|
||
return ratio; | ||
} | ||
}; | ||
|
||
private String name; | ||
private Employee.Type type; | ||
private long salary; | ||
|
||
public Employee(String name, int type, long salary) { | ||
setName(name); | ||
setType(type); | ||
setSalary(salary); | ||
} | ||
|
||
public Employee(String name, Employee.Type type, long salary) { | ||
setName(name); | ||
setType(type); | ||
setSalary(salary); | ||
} | ||
|
||
public void setName(String name) {this.name = name;} | ||
public void setType(Employee.Type type) {this.type = type;} | ||
public void setType(int type) throws RuntimeException { | ||
switch (type) { | ||
case 1 : this.type = Type.OWNER; break; | ||
case 2 : this.type = Type.MANAGER; break; | ||
case 3 : this.type = Type.DESIGNER; break; | ||
case 4 : this.type = Type.ARCHITECT; break; | ||
case 5 : this.type = Type.DEVELOPER; break; | ||
default: | ||
throw new RuntimeException("Unsupported type encountered : " + type); | ||
} | ||
} | ||
public void setSalary(long salary) {this.salary = salary;} | ||
|
||
public String getName() {return name;} | ||
public Employee.Type getType() {return type;} | ||
public long getSalary() {return salary;} | ||
public double getRatio() {return this.type.getRatio();} | ||
} |
This file contains 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 @@ | ||
|
||
### <자바의 신> 중간 점검 및 실습 - 실습 문제 | ||
|
||
- [`문제 설명`](./README.md) | ||
|
||
--- | ||
|
||
중간 점검 문제도 설명을 따라 구현하면 어렵지 않다. | ||
|
||
다만 만들다 중간에 따르지 않은 부분이 있는데, `Employee` 클래스에 `int type` 필드이다. `type` 필드는 직원들의 `type` 을 구분하기 위한 필드인데, 이를 그냥 `int` 보다는 `enum` 상수로 만드는 게 더 나을 것 같다는 생각이 들었다. | ||
|
||
그래서 `Employee` 클래스 내에 `Type` 이라는 `Enum` 클래스를 만들었고, 편의를 위해 연봉 인상율을 반환하는 `getRatio` 메서드도 만들었다. | ||
|
||
그 외에는 최대한 동일하게 만들었다. |
This file contains 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,31 @@ | ||
|
||
### `자바의 신 : VOL.1 기초 문법편 3판` 총정리 | ||
|
||
`자바의 신 3판, 기초 문법편` 을 공부한 내용을 간략하게 정리한 파일입니다. | ||
|
||
--- | ||
|
||
### 교재 정리 | ||
|
||
- #### [`Chapter 1 ~ 6`](./ch_01_06.md) | ||
- #### [`Chapter 7 ~ 13`](./ch_07_13.md) | ||
- #### [`Chapter 14 ~ 17`](./ch_14_17.md) | ||
|
||
--- | ||
|
||
### <자바의 신> 중간 점검 및 실습 | ||
|
||
- #### [`요약 문제`](../GOJ_mid_check/overview_problems/README.md) | ||
- #### [`실습 문제`](../GOJ_mid_check/practice_problems/solution.md) | ||
|
||
--- | ||
|
||
### 기타 공부 내용 정리 | ||
|
||
- ##### [`Java 가 실행되는 과정`](../ch_01/extra/how_does_java_works.md) | ||
|
||
- ##### [`Java 와 C++ 에서의 default constructor`](../ch_03/extra/difference_of_default_constructor_in_java_and_cpp.md) | ||
|
||
- ##### [`byte 는 원래 8 bit 가 아니었다고?`](../ch_04/README.md) | ||
|
||
--- |
This file contains 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,104 @@ | ||
|
||
### `자바의 신 : VOL.1 기초 문법편 3판` 총정리, `Chapter 1 ~ 6` | ||
|
||
--- | ||
|
||
- ### `키워드` 와 `예약어` | ||
|
||
`Java` 에는 `키워드` 와 `예약어` 가 있다. `키워드` 는 `프로그래밍 언어에서 이미 사전 정의된 단어` 이고, `예약어` 는 `키워드는 아니지만 식별자로 쓰일 수 없는 단어` 이다. | ||
|
||
이처럼 둘을 구분짓는 것은 버전 별 `상위 호환성` `(Forward compatibility)` 을 맞추고, 하위 버전 프로그램의 안정성을 도모하기 위함이다. | ||
|
||
- ### [`Java 의 예약어 정리`](../ch_03/extra/reserved_words_in_java.md) | ||
|
||
--- | ||
|
||
- ### `Java` 의 변수 | ||
`Java` 에 존재하는 변수는 크게 4 가지로 나눌 수 있다. | ||
|
||
- 인스턴스 변수 `(Instance Variable)` | ||
|
||
인스턴스 변수는 클래스 필드에 선언된 변수로, `non-static` 하게 선언된 변수이다. | ||
|
||
- 클래스 변수 `(Class Variable)` | ||
|
||
클래스 변수는 클래스 필드에 `static` 하게 선언된 변수이다. | ||
|
||
- 지역 변수 `(Local Variable)` | ||
|
||
지역 변수는 어느 블럭에서만 수명이 유지되는 변수를 뜻한다. 지역 변수는 생성시 `stack` 에 저장되고, 블럭을 벗어날시 참조할 수 없으며 수명 또한 보장되지 않는다. | ||
|
||
- 매개 변수 `(Parameter)` | ||
|
||
메서드 호출 시 메서드로 넘겨지는 변수들을 말한다. 메서드로 넘겨지는 방식은 `pass by value`, `pass by reference` 가 있으며 이는 각각 `primitive types`, `reference type` 인 매개변수을 사용할 때 이루어진다. | ||
|
||
이 중 인스턴스 변수는 객체의 수명과 동일한 수명을 가졌으나, 클래스 변수는 `static` 하므로 프로그램의 수명과 동일하다. | ||
|
||
- ### `Java` 의 기본 자료형 8 가지 | ||
|
||
`Java` 의 기본 자료형은 총 8 개 이고, 이는 크게 다음 3 가지로 나눌 수 있다. | ||
|
||
- `Numeric type` | ||
|`type`|`storage`|`usage`| | ||
|---|---|---| | ||
|`byte`|`1 byte`|`signed 8-bit field` 에 관한 연산을 진행할 수 있음| | ||
|`char`|`2 byte`|한 문자를 표현. `16-bit Unicode` 이용| | ||
|`short`|`2 byte`|반쪽자리 `int`| | ||
|`int`|`4 byte`|일반적인 정수 표현| | ||
|`long`|`8 byte`|`int` 2 배| | ||
|
||
- `Floating point type` | ||
|`type`|`storage`|`usage`| | ||
|---|---|---| | ||
|`float`|`4 byte`|단 정밀도 부동소수점 표현| | ||
|`double`|`8 byte`|배 정밀도 부동소수점 표현| | ||
|
||
- `Boolean type` | ||
|`type`|`storage`|`usage`| | ||
|---|---|---| | ||
|`bool`|`1 byte`|`true` or `false` 에 해당하는 값 이용| | ||
|
||
`Java` 에서 `Numeric type` 들은 대개 `부호 있는 값` `(signed values)` 들 이다. 하지만 `char` 만 예외적으로 `unsigned value` 이다. | ||
|
||
또한 기본 자료형 간 `형 변환` 은 `Numeric types <--> Floating point types` 만 가능하다. `bool` 은 어떤 방식으로든 형 변환이 불가능하다. | ||
|
||
덧붙여 이들이 `클래스 변수` 와 같이 것으로 선언되었을 때, 기본적으로 초기화 되는 값들은 다음과 같다. | ||
|
||
|`Type`|`Default value`| | ||
|:---:|:---:| | ||
|`byte`|`0`| | ||
|`short`|`0`| | ||
|`int`|`0`| | ||
|`long`|`0L`| | ||
|`char`|`0`| | ||
|`float`|`0.0f`| | ||
|`double`|`0.0d`| | ||
|`boolean`|`0, \u0000`| | ||
|`Reference`|`null`| | ||
|
||
--- | ||
|
||
- ### `Java` 의 `swtich` 구문 | ||
|
||
`Java` 에도 `switch` 구문이 존재한다. `C` 에서 `switch` 는 정수형 값만 사용될 수 있다. 하지만 `Java` 는 다음과 같은 타입도 가능하다. | ||
|
||
- `Numeric Type` : `long` 을 제외한 `Numeric Type` | ||
|
||
|
||
`byte`, `char`, `short`, `int` | ||
|
||
- 사용 가능한 `Numeric Type` 의 `Wrapper class` | ||
|
||
`Byte`, `Character`, `Short`, `Integer` | ||
|
||
- 몇몇 참조형 타입 | ||
|
||
`Enum` `(enumerated types)`, `String` `(Java 7 부터 추가)` | ||
|
||
- ### `label in for loop` | ||
|
||
`Java` 에서 `nested loop` 를 중단시킬 때, `label` 이라는 것을 이용해 중단시킬 수도 있다. 많이 사용되지는 않지만 처음 본 내용이라 정리하였다. | ||
|
||
- [`예시 및 설명`](../ch_06/section_03_06.md#6-많이-사용-안하는-label) | ||
|
||
--- |
Oops, something went wrong.