-
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.
chapter 08 : 참조 자료형에 대해서 더 자세히 알아봅시다
공부 내용 정리 완료
# `chapter 08 : 참조 자료형에 대해서 더 자세히 알아봅시다` 공부 내용 정리 완료 --- <<< Merge remote-tracking branch 'origin/main' into test - `gitignore` 에 `.vscode/` 추가 --- * 공부 내용 동기화 `commit` * 문서 형식 수정 * 내용 추가 및 틀린 내용 수정 - 문서 형식 수정 - 관련 내용 추가 - 틀린 내용 수정 : `Java 의 예약어 / 키워드 정리` * 공부 내용 동기화 `commit` - `chapter 08 : 참조 자료형에 대해서 더 자세히 알아봅시다` 공부 내용 정리 완료 * 설명 추가 * `ch_07 solution` 빈 `Reference` 삭제 * 이전 참고 자료 이름 수정
- Loading branch information
Showing
14 changed files
with
408 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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,16 @@ | ||
|
||
### Chapter 08 : 참조 자료형에 대해서 더 자세히 알아봅시다 | ||
|
||
- [`2. 기본 생성자`](./section_02_09.md) | ||
- [`9. static 블럭`](./section_02_09.md) | ||
- [`10. Pass by value, Pass by reference`](./section_10_11.md) | ||
- [`11. 매개 변수를 지정하는 특이한 방법`](./section_10_11.md) | ||
|
||
|
||
### What I learned from this chapter | ||
|
||
이번 챕터에는 그나마 흥미로운 내용들이 있었다. 디자인 패턴과 관련된 내용도 살짝 나왔고, `Arbitary Number of Arguments` 도 나왔다. | ||
|
||
`Arbitary Number of Arguments` 를 이용한 `System.out.printf` 메서드도 활용해 보았고, `static block` 에 대한 몰랐던 사실 또한 알게 되었다. | ||
|
||
그리고 나중에 디자인 패턴도 공부해야 된다는 사실을 상기할 수 있었다. |
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,69 @@ | ||
package scripts.ch_08.code; | ||
|
||
interface Required_methods_1 { | ||
String toString(); | ||
} | ||
|
||
class Student implements Required_methods_1 { | ||
private String name, address, phone, email; | ||
private String[] Array = { | ||
name, address, phone, email | ||
}; | ||
|
||
public Student(String ... args) | ||
{ | ||
for (int i = 0; i < args.length; i++) | ||
{ | ||
this.Array[i] = args[i]; | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
String concateString = ""; | ||
for (String var : Array) | ||
{ | ||
if (var != null) {concateString += var + " ";} | ||
else {concateString += "None ";} | ||
} | ||
|
||
return concateString; | ||
} | ||
} | ||
|
||
interface Required_methods_2 { | ||
Student[] addStudents(); | ||
} | ||
|
||
public class ManageStudent implements Required_methods_2 { | ||
public static void main(String[] args) { | ||
ManageStudent test = new ManageStudent(); | ||
Student[] student = test.addStudents(); | ||
|
||
test.printStudents(student); | ||
} | ||
|
||
@Override | ||
public Student[] addStudents() | ||
{ | ||
Student[] student = new Student[3]; | ||
student[0] = new Student("Lim"); | ||
student[1] = new Student("Min"); | ||
student[2] = new Student( | ||
"Sook", "Seoul", | ||
"010xxxxxxxx", "ask@godofjava.com" | ||
); | ||
|
||
return student; | ||
} | ||
|
||
public void printStudents(Student ... students) | ||
{ | ||
for (Student single_student : students) | ||
{ | ||
System.out.println(single_student); | ||
} | ||
} | ||
} | ||
|
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,44 @@ | ||
|
||
### Chapter 08 : 참조 자료형에 대해서 더 자세히 알아봅시다 - 정리해 봅시다. | ||
|
||
- `[1]` : `Student` 라는 클래스를 만들고, `name`, `address`, `phone`, `email` 이라는 인스턴스 변수를 `String` 타입으로 선언하자. | ||
- `[2]` : 학생의 정보에 이름은 반드시 입력되어야 하므로, `name` 을 받아서 인스턴스 변수에 할당해 주는 `Student` 클래스의 생성자를 만들자. | ||
- `[3]` : 모든 학생의 정보를 생성하면서 할당하는 `name`, `address`, `phone`, `email` 을 매개 변수로 받아 인스턴스 변수에 할당하는 `Student` 클래스의 생성자를 만들자. | ||
- `[4]` : 다음과 같이 학생의 정보들을 `String` 으로 리턴하는 `toString()` 이라는 메서드를 만들자. | ||
|
||
```java | ||
public String toString() { | ||
return name + " " + address + " " + phone + " " + email; | ||
} | ||
``` | ||
|
||
- `[5]` : 학생 정보를 담아두는 `Student` 클래스는 다 작성했으니, 학생들을 관리하는 `ManageStudent` 라는 클래스를 만들자. | ||
- `[6]` : `ManageStudent` 클래스에 `main()` 메서드를 만들자. | ||
- `[7]` : 다음과 같이 배열을 매개 변수로 받아 학생의 정보를 담은 후 리턴하는 메서드를 만들자. | ||
|
||
```java | ||
public Student[] addStudent() { | ||
Student[] student = new Student[3]; | ||
student[0] = new Student("Lim"); | ||
student[1] = new Student("Min"); | ||
student[2] = new Student( | ||
"Sook", "Seoul", | ||
"010xxxxxxxx", "ask@godofjava.com" | ||
); | ||
|
||
return student; | ||
} | ||
``` | ||
|
||
- `[8]` : `main()` 메서드에서 `student` 라는 이름을 갖는 `Student` 배열을 만들고, 별도의 초기화는 하지 말고, `null` 로 할당하자. | ||
- `[9]` : `main()` 메서드에서 `addStudent()` 메서드를 호출하고, 그 결과를 `student` 객체로 받자. | ||
- `[10]` : `student` 객체의 내용을 출력할 `printStudents()` 라는 메서드를 만들고, 매개 변수로는 `student` 객체를 받을 수 있도록 하자. | ||
- `[11]` : `printStudents()` 메서드에서 `for` 문을 사용하여 `student` 배열의 각각의 내용을 출력하자. | ||
- `[12]` : `main()` 메서드에서 `printStudents()` 메서드를 호출하자. | ||
- `[13]` : `ManageStudent` 클래스를 컴파일 한 후 실행해보자. 결과는 다음과 같이 출력되어야 한다. | ||
|
||
``` | ||
Lim null null null | ||
Min null null null | ||
Sook Seoul 010xxxxxxxx ask@godofjava.com | ||
``` |
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,13 @@ | ||
|
||
### Chapter 08 : 참조 자료형에 대해서 더 자세히 알아봅시다 - 정리해 봅시다. | ||
|
||
- [`문제 설명`](./README.md) | ||
|
||
--- | ||
|
||
대부분 문제에서 요구한 대로 구현하였다. 그래도 심심해서 `Student` 의 인스턴수 변수를 담을 배열을 선언하고, 생성자 호출 시 이를 이용하는 방식을 사용했다. `(임의 개수 parameter 이용)` | ||
|
||
그리고 `ManageStudent` 에서 각 학생들의 정보를 출력하라 하였는데, `Student` 에서 `toString` 메서드를 만들은 것을 이용하였다. | ||
|
||
`(toString 메서드가 존재할 시, 해당 객체를 출력하면 toString 의 반환값으로 출력된다)` | ||
[`(이전 Chapter 7 : 3. 배열을 그냥 출력해보면 어떻게 나올까? 설명 참조)`](../../ch_07/section_01_03.md#3-배열을-그냥-출력해보면-어떻게-나올까) |
Oops, something went wrong.