-
Notifications
You must be signed in to change notification settings - Fork 5
[최현식] 3주차 - 7장, 8장 #13
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
Open
Open
Changes from all commits
Commits
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
116 changes: 116 additions & 0 deletions
hyeonsik/docs/C07/README.md
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,116 @@ | ||
| ## 배열의 기본값 | ||
|
|
||
| - 배열 선언(초기화)시 크기가 지정되어야 한다. | ||
| - 중간에 배열 크기를 증감시킬 순 없다. | ||
| - 기본 자료형 배열의 기본값은 각 자료형의 기본값과 동일 | ||
| - 지역변수의 경우 초기화를 하지 않으면 사용이 불가능하지만, 배열은 크기만 정해주면 사용이 가능하다. | ||
| - 기본값 | ||
| - 0, 0.0, false, `\u0000` | ||
| - 참고로 참조자료형의 경우 null이 초기값이다. | ||
|
|
||
| `[Ljava.lang.String;@1540e19d` | ||
|
|
||
| - [L: [배열객체, L참조자료형 | ||
| - java.langString: Type | ||
| - @1123123: 고유번호 → 써먹을데가없다? 해쉬 비교? | ||
|
|
||
| - 당연하지만 메소드체이닝은 참조자료형에만 사용할 수 있다. | ||
|
|
||
| ### Java5 Style For loop | ||
|
|
||
| - index를 알 필요가 없을때 좋다 | ||
|
|
||
| ```java | ||
| for(type name : items) { | ||
| }ᄀ | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 책 | ||
|
|
||
| ### 직접해 봅시다 | ||
|
|
||
| ```java | ||
| public class ManageHeight { | ||
| private int[][] student; | ||
|
|
||
| public void setData() { | ||
| student = new int[][]{ | ||
| {170, 180, 173, 175, 177}, | ||
| {160, 165, 167, 186}, | ||
| {158, 177, 187, 176}, | ||
| {173, 182, 181}, | ||
| {170, 180, 165, 177, 172} | ||
| }; | ||
| } | ||
|
|
||
| public void printHeight(int classNo) { | ||
| System.out.println("Class No.:" + classNo); | ||
| for(int student : student[classNo]) { | ||
| System.out.println(student); | ||
| } | ||
| } | ||
|
|
||
| public void printAverage(int classNo) { | ||
| System.out.println("Class No.:" + classNo); | ||
|
|
||
| int i = 0; | ||
| int studentHeightTotal = 0; | ||
| for(int student : student[classNo]) { | ||
| i++; | ||
| studentHeightTotal += student; | ||
| } | ||
| System.out.println("Height average:" + (double) studentHeightTotal / i); | ||
| } | ||
|
|
||
| } | ||
| ``` | ||
|
|
||
| ```java | ||
| class ManageHeightTest { | ||
| private ManageHeight manageHeight; | ||
|
|
||
| @BeforeEach | ||
| void before() { | ||
| manageHeight = new ManageHeight(); | ||
| manageHeight.setData(); | ||
| } | ||
|
|
||
| @Test | ||
| void printHeight() { | ||
| for (int i = 0; i < 5; i++) { | ||
| manageHeight.printHeight(i); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void printAverage() { | ||
| int i = 0; | ||
| while (i < 5) { | ||
| manageHeight.printAverage(i); | ||
| i++; | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### 정리해 봅시다 | ||
|
|
||
| 1. 배열을 선언할 때 어떤 키워드를 타입 앞이나 뒤에 사용해야 하나요? | ||
| - [] | ||
| 2. 배열의 첫번째 위치는 0인가요? 1인가요? | ||
| - 0 | ||
| 3. 배열을 선언할 때 boolean 배열의 크기만 지정했다면 boolean 배열의 [0]에 위치에 잇는 값은 무엇인가요? | ||
| - false | ||
| 4. 중괄호를 이용하여 배열을 초기화 할 때 중괄호 끝에 반드시 어떤 것을 입력해 주어야 하나요? | ||
| - ; | ||
| 5. 2차원 배열을 정의할 때에는 대괄호를 몇 개 지정해야 하나요? | ||
| - 2개 이상 (2차원 인덱스 수에 따라 다름) | ||
| 6. 배열을 쉽게 처리해주는 for문의 문법은 어떻게 되나요? | ||
| - for (type name : items) | ||
| - java5 이상부터 사용 가능함 | ||
| 7. 자바 프로그램에 데이터를 전달해 주려면 클래스 이름 뒤에 어떻게 구분하여 나열하면 되나요? | ||
| - args는 공란으로 구분지어서 나열하면된다. | ||
| 8. 자바 프로그램이 시작할 때 전달 받는 내용은 어떤 타입의 배열인가요? | ||
| - string (String args[]) |
100 changes: 100 additions & 0 deletions
hyeonsik/docs/C08/README.md
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,100 @@ | ||
| ## 참조 자료형 | ||
|
|
||
| - 기본 생성자는 다른 생성자가 존재한다면 자동으로 만들어지지 않는다. | ||
|
|
||
| --- | ||
|
|
||
| ## 책 | ||
|
|
||
| ### 직접해 봅시다 | ||
|
|
||
| ```java | ||
| public class Student { | ||
| private String name; | ||
| private String address; | ||
| private String phone; | ||
| private String email; | ||
|
|
||
| public Student(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public Student(String name, String address, String phone, String email) { | ||
| this.name = name; | ||
| this.address = address; | ||
| this.phone = phone; | ||
| this.email = email; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return name + " " + address + " " + phone + " " + email; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ```java | ||
| public class ManageStudent { | ||
| public Student[] addStudent() { | ||
| Student[] student = new Student[3]; | ||
| student[0] = new Student("Lim"); | ||
| student[1] = new Student("Min"); | ||
| student[2] = new Student("Sook", "Seoul", "010123456768", "aaa@mail.com"); | ||
| return student; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ```java | ||
| class ManageStudentTest { | ||
| private final ManageStudent manageStudent = new ManageStudent(); | ||
|
|
||
| @Test | ||
| void addStudent() { | ||
| Student[] student; | ||
|
|
||
| student = manageStudent.addStudent(); | ||
|
|
||
| assertAll( | ||
| () -> assertEquals(student[0].toString(), "Lim null null null"), | ||
| () -> assertEquals(student[1].toString(), "Min null null null"), | ||
| () -> assertEquals(student[2].toString(), "Sook Seoul 010123456768 aaa@mail.com") | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| void printStudent() { | ||
| Student[] student; | ||
|
|
||
| student = manageStudent.addStudent(); | ||
|
|
||
| for (Student stu : student) { | ||
| System.out.println(stu.toString()); | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### 정리해 봅시다 | ||
|
|
||
| 1. 생성자는 반드시 만들어야 하나요? | ||
| - 아니요, 안적으면 기본생성자 자동생성됨 | ||
| 2. 만약 매개 변수가 있는 생성자를 만들고, 매개 변수가 없는 기본 생성자를 호출하면 어떻게 될까요? | ||
| - 없으므로 오류발생! | ||
| 3. 생성자의 개수는 제한이 있나요? | ||
| - 없다 | ||
| 4. 인스턴스의 변수와 매개 변수나 메소드 내에서 생성한 변수와 구분하기 위해서 사용하는 키워드는 무엇인가요? | ||
| - this | ||
| 5. 메소드 선언시 아무 데이터도 리턴 타입으로 넘겨주지 않겠다는 것을 지정하는 키워드는 무엇인가요? | ||
| - void | ||
| 6. 메소드 선언에 static이 있는 것과 없는 것의 차이는 무엇인가요? | ||
| - 객체 생성없이 해당 메소드를 호출할 수 있다. | ||
| 7. 필자가 엄청나게 중요하다고 한 것 중 메소드의 이름은 같으나 매개 변수를 다르게 하는 것의 명칭은 무엇인가요? | ||
| - overloading | ||
| 8. 기본 자료형을 매개 변수로 넘겨 줄 때 pass by value인가요? pass by reference 인가요? | ||
| - value | ||
| 9. 참조 자료형은? | ||
| - reference | ||
| 10. 매개 변수의 수가 가변적일 때 메소드 선언시 타입과 변수 이름 사이에 어떤 것을 적어줘야 하나요? | ||
| - ... (가변인자) |
35 changes: 35 additions & 0 deletions
hyeonsik/java-project-for-test/untitled/src/test/java/C07/ManageHeight.java
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,35 @@ | ||
| package C07; | ||
|
|
||
| public class ManageHeight { | ||
| private int[][] student; | ||
|
|
||
| public void setData() { | ||
| student = new int[][]{ | ||
| {170, 180, 173, 175, 177}, | ||
| {160, 165, 167, 186}, | ||
| {158, 177, 187, 176}, | ||
| {173, 182, 181}, | ||
| {170, 180, 165, 177, 172} | ||
| }; | ||
| } | ||
|
|
||
| public void printHeight(int classNo) { | ||
| System.out.println("Class No.:" + classNo); | ||
| for(int student : student[classNo]) { | ||
| System.out.println(student); | ||
| } | ||
| } | ||
|
|
||
| public void printAverage(int classNo) { | ||
| System.out.println("Class No.:" + classNo); | ||
|
|
||
| int i = 0; | ||
| int studentHeightTotal = 0; | ||
| for(int student : student[classNo]) { | ||
| i++; | ||
| studentHeightTotal += student; | ||
| } | ||
| System.out.println("Height average:" + (double) studentHeightTotal / i); | ||
| } | ||
|
|
||
| } |
30 changes: 30 additions & 0 deletions
hyeonsik/java-project-for-test/untitled/src/test/java/C07/ManageHeightTest.java
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,30 @@ | ||
| package C07; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class ManageHeightTest { | ||
| private ManageHeight manageHeight; | ||
|
|
||
| @BeforeEach | ||
| void before() { | ||
| manageHeight = new ManageHeight(); | ||
| manageHeight.setData(); | ||
| } | ||
|
|
||
| @Test | ||
| void printHeight() { | ||
| for (int i = 0; i < 5; i++) { | ||
| manageHeight.printHeight(i); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void printAverage() { | ||
| int i = 0; | ||
| while (i < 5) { | ||
| manageHeight.printAverage(i); | ||
| i++; | ||
| } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
hyeonsik/java-project-for-test/untitled/src/test/java/C08/ManageStudent.java
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,11 @@ | ||
| package C08; | ||
|
|
||
| public class ManageStudent { | ||
| public Student[] addStudent() { | ||
| Student[] student = new Student[3]; | ||
| student[0] = new Student("Lim"); | ||
| student[1] = new Student("Min"); | ||
| student[2] = new Student("Sook", "Seoul", "010123456768", "aaa@mail.com"); | ||
| return student; | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
hyeonsik/java-project-for-test/untitled/src/test/java/C08/ManageStudentTest.java
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,34 @@ | ||
| package C08; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class ManageStudentTest { | ||
| private final ManageStudent manageStudent = new ManageStudent(); | ||
|
|
||
| @Test | ||
| void addStudent() { | ||
| Student[] student; | ||
|
|
||
| student = manageStudent.addStudent(); | ||
|
|
||
| assertAll( | ||
| () -> assertEquals(student[0].toString(), "Lim null null null"), | ||
| () -> assertEquals(student[1].toString(), "Min null null null"), | ||
| () -> assertEquals(student[2].toString(), "Sook Seoul 010123456768 aaa@mail.com") | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| void printStudent() { | ||
| Student[] student; | ||
|
|
||
| student = manageStudent.addStudent(); | ||
|
|
||
| for (Student stu : student) { | ||
| System.out.println(stu.toString()); | ||
| } | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
hyeonsik/java-project-for-test/untitled/src/test/java/C08/Student.java
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,24 @@ | ||
| package C08; | ||
|
|
||
| public class Student { | ||
| private String name; | ||
| private String address; | ||
| private String phone; | ||
| private String email; | ||
|
|
||
| public Student(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public Student(String name, String address, String phone, String email) { | ||
| this.name = name; | ||
| this.address = address; | ||
| this.phone = phone; | ||
| this.email = email; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return name + " " + address + " " + phone + " " + email; | ||
| } | ||
| } |
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.