-
Notifications
You must be signed in to change notification settings - Fork 5
[박재홍] CHAPTER 7 ~ 8 #14
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
JaeHongDev
wants to merge
2
commits into
Invincible-Backend-Study:JaehongDev
from
JaeHongDev:chapter7
Open
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
61 changes: 61 additions & 0 deletions
jaehong/chapter7/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,61 @@ | ||
| import java.util.*; | ||
| import java.util.stream.*; | ||
| public class ManageHeight{ | ||
|
|
||
| private int[][] gradeHeights = new int[5][]; | ||
|
|
||
| public static void main(String...args){ | ||
| final var manageHeight = new ManageHeight(); | ||
| manageHeight.setData(); | ||
|
|
||
| manageHeight.printHeight(); | ||
| manageHeight.printAverage(); | ||
| } | ||
|
|
||
| public void setData(){ | ||
| this.insert(1, new int[]{170,180,173,175,177}); | ||
| this.insert(2, new int[]{160,165,167,186 }); | ||
| this.insert(3, new int[]{158,177,187,176}); | ||
| this.insert(4, new int[]{173, 182,181}); | ||
| this.insert(5, new int[]{170,180,165,177,172}); | ||
| } | ||
| private void insert(int grade, int[] heights){ | ||
| this.gradeHeights[grade - 1] = heights; | ||
| } | ||
|
|
||
| public void printHeight(){ | ||
| System.out.println("결과"); | ||
| IntStream.range(0, gradeHeights.length).forEach(this::printHeight); | ||
| } | ||
|
|
||
| public void printHeight(int classNo){ | ||
| var grade = gradeHeights[classNo]; | ||
| var sb = new StringBuilder(); | ||
|
|
||
| sb.append(String.format("Class No.:%d", classNo+1 )) | ||
| .append("\n") | ||
| .append(Arrays.stream(grade).mapToObj(String::valueOf).collect(Collectors.joining("\n"))) | ||
| .append("\n"); | ||
|
|
||
| System.out.print(sb); | ||
| } | ||
|
|
||
| public void printAverage(){ | ||
| System.out.println("결과"); | ||
| IntStream.range(0, gradeHeights.length).forEach(this::printAverage); | ||
| } | ||
|
|
||
| public void printAverage(int classNo){ | ||
| final var sb = new StringBuilder(); | ||
| var grade = gradeHeights[classNo]; | ||
|
|
||
| sb.append(String.format("Class No.:%d", classNo+1 )).append("\n") | ||
| .append("Height average:") | ||
| .append(Arrays.stream(grade).average().getAsDouble()) | ||
| .append("\n"); | ||
|
|
||
| System.out.print(sb); | ||
|
|
||
| } | ||
|
|
||
| } |
24 changes: 24 additions & 0 deletions
jaehong/chapter8/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,24 @@ | ||
| public class ManageStudent{ | ||
|
|
||
| public static void main(String...args){ | ||
| Student[] student; | ||
| var manageStudent = new ManageStudent(); | ||
| student = manageStudent.addStudent(); | ||
| manageStudent.printStudent(student); | ||
|
|
||
| } | ||
|
|
||
| public Student[] addStudent(){ | ||
| var student = new Student[3]; | ||
| student[0] = new Student("Lim"); | ||
| student[1] = new Student("Min"); | ||
| student[2] = new Student("Seok", "Seoul", "010xxxxxxx","println@kakao.com"); | ||
| return student; | ||
| } | ||
|
|
||
| public void printStudent(Student[] student){ | ||
| for(var std: student){ | ||
| System.out.println(std.toString()); | ||
| } | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
jaehong/chapter8/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,26 @@ | ||
|
|
||
| public class Student{ | ||
| private String name; | ||
| private String address; | ||
| private String phone; | ||
| private String email; | ||
|
|
||
| public Student(final String name, String address, String phone, String email){ | ||
| this.name = name; | ||
| this.address = address; | ||
| this.phone = phone; | ||
| this.email = email; | ||
| } | ||
|
|
||
| public Student(final String name){ | ||
|
|
||
| this.name = name; | ||
| } | ||
|
|
||
|
|
||
| @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.