-
Notifications
You must be signed in to change notification settings - Fork 0
[학과 생성자 프로그램] 유소영 제출합니다. #9
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
base: 1028ragon
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Department 클래스 정의 | ||
| public class Department { | ||
|
|
||
| // 필드 정의 | ||
| String name; | ||
| int studentCount; | ||
| String building; | ||
|
|
||
| // 생성자 | ||
| public Department(String name, int studentCount, String building) { | ||
| this.name = name; // 전달받은 것을 필드에 저장 | ||
| this.studentCount = studentCount; | ||
| this.building = building; | ||
| } | ||
|
|
||
| // 메서드 | ||
| // 학과 정보를 출력하는 메서드 | ||
| public void printInfo() { | ||
| System.out.println("학과명: " + name); | ||
| System.out.println("학생수: " + studentCount); | ||
| System.out.println("건물: " + building); | ||
| } | ||
|
1028ragon marked this conversation as resolved.
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // 실행 클래스 | ||
| public class Main { | ||
| public static void main(String[] args) { | ||
|
|
||
| // 객체 생성 | ||
| Department d1 = new Department("컴퓨터공학과", 65, "기도관"); | ||
| Department d2 = new Department("경영학과", 200, "에벤에셀관"); | ||
| Department d3 = new Department("에너지공학과", 60, "기도관"); | ||
|
|
||
| /* Department[] departments = {d1, d2, d3}; | ||
|
|
||
| for (Department d : departments) { | ||
| System.out.println("학과명 : " + d.name + ", 학생수 : " + d.studentCount + ", 건물 : " + d.building); | ||
| } */ | ||
|
|
||
|
1028ragon marked this conversation as resolved.
|
||
| // 메서드 호출 | ||
| d1.printInfo(); | ||
| d2.printInfo(); | ||
| d3.printInfo(); | ||
|
Comment on lines
+16
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메서드 호출 부분도 전반적으로 잘 작성해주셨습니다. 특히 printInfo()와 같이 메서드를 활용하여 객체의 정보를 출력하도록 구성하신 점을 보았을 때, 메서드 활용에 대한 이해도가 잘 잡혀 있는 것으로 보입니다. 다만, 현재는 각 객체에 대해 동일한 호출문을 반복적으로 작성하고 있는데, 이 부분은 확장된 for문을 활용하여 반복 출력하는 방식으로 개선해볼 수 있을 것 같습니다. 이번 과제에서는 객체가 3개로 제한되어 있어 큰 차이가 없지만, 추후 객체 수가 증가하는 상황을 고려하면 현재 방식은 유지보수 측면에서 비효율적일 수 있으며 코드의 복잡성도 함께 증가할 수 있습니다. 메서드를 활용한 구조는 충분히 잘 구성되어 있으므로, 호출 방식에 대해서도 반복문을 활용하는 방향으로 한 번 더 고민해보시면 좋을 것 같습니다.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 피드백을 확인해서 반복문을 활용하면 코드 중복을 줄일 수 있다는 점을 확인했습니다. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # 과제명 | ||
| 학과 생성자 프로그램 | ||
|
|
||
| ## ⚙️ 실행 방법 | ||
| 1. 터미널에서 해당 폴더로 이동한다 : | ||
| `cd 파일경로` | ||
|
|
||
| 2. Java 파일을 컴파일한다 : | ||
| `javac Main.java` | ||
|
|
||
| 3. 프로그램을 실행한다 : | ||
| `java Main` | ||
| ## 💡 작업 내용 | ||
| - Department 클래스를 생성 | ||
| - 필드(name, studentCount, building)정의 | ||
| - Main 클래스에서 여러 Department 객체를 생성 | ||
| - printInfo() 메서드를 구현하여 학과 정보 출력 | ||
|
|
||
| ## 🤔 느낀 점 / 어려웠던 점 | ||
| - 처음에 확장된 for문을 사용해 배열로 구현했다가, 이번주차 강의와 맞게 저번과는 다르게 구현해보자 하여 메서드를 사용해 보았다. |
Uh oh!
There was an error while loading. Please reload this page.