Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions java-oop-1/Department.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Department 클래스 정의
public class Department {

// 필드 정의
String name;
int studentCount;
String building;
Comment thread
Donghwan814 marked this conversation as resolved.

// 생성자
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);
}
Comment thread
1028ragon marked this conversation as resolved.
}
21 changes: 21 additions & 0 deletions java-oop-1/Main.java
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);
} */

Comment thread
1028ragon marked this conversation as resolved.
// 메서드 호출
d1.printInfo();
d2.printInfo();
d3.printInfo();
Comment on lines +16 to +19
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메서드 호출 부분도 전반적으로 잘 작성해주셨습니다. 특히 printInfo()와 같이 메서드를 활용하여 객체의 정보를 출력하도록 구성하신 점을 보았을 때, 메서드 활용에 대한 이해도가 잘 잡혀 있는 것으로 보입니다.

다만, 현재는 각 객체에 대해 동일한 호출문을 반복적으로 작성하고 있는데, 이 부분은 확장된 for문을 활용하여 반복 출력하는 방식으로 개선해볼 수 있을 것 같습니다.

이번 과제에서는 객체가 3개로 제한되어 있어 큰 차이가 없지만, 추후 객체 수가 증가하는 상황을 고려하면 현재 방식은 유지보수 측면에서 비효율적일 수 있으며 코드의 복잡성도 함께 증가할 수 있습니다.

메서드를 활용한 구조는 충분히 잘 구성되어 있으므로, 호출 방식에 대해서도 반복문을 활용하는 방향으로 한 번 더 고민해보시면 좋을 것 같습니다.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

피드백을 확인해서 반복문을 활용하면 코드 중복을 줄일 수 있다는 점을 확인했습니다.
앞으로는 배열, 확장된 for문, 메서드를 함꼐 유동적으로 활용하는 방향으로 개선해보겠습니다!

}
}
20 changes: 20 additions & 0 deletions java-oop-1/README.md
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문을 사용해 배열로 구현했다가, 이번주차 강의와 맞게 저번과는 다르게 구현해보자 하여 메서드를 사용해 보았다.