-
Notifications
You must be signed in to change notification settings - Fork 0
[객체 배열 관리 프로그램] 이민구 제출합니다 #4
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: LEEMINGU03
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,17 @@ | ||
| import model.Student; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| Student s1 = new Student("김멋사","20260001","Software"); | ||
| Student s2 = new Student("김동사","20250001","Hardware"); | ||
| Student s3 = new Student("김수사","20240001","AI"); | ||
|
|
||
| Student[] students = {s1,s2,s3}; | ||
|
|
||
| Student.printAll(students); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # 과제명 | ||
| java-basic (2주차 과제) | ||
|
|
||
| ## ⚙️ 실행 방법 | ||
| ### 1. 터미널(Terminal)에서 명령어로 실행 | ||
| **1단계: 컴파일 (Compile)** | ||
| ```bash | ||
| javac -d out java-basic/Main.java java-basic/model/Student.java | ||
| ``` | ||
| **2단계: 실행** | ||
| ```bash | ||
| java -cp out Main | ||
| ``` | ||
| ## 💡 작업 내용 | ||
| ### 1. `java-basic/model/Student.java` | ||
| - **역할**: 학생 정보를 저장하고 관리하는 **Student** 클래스입니다. | ||
| - **주요 내용**: | ||
| - 학생의 속성(이름, 학번, 전공 등)을 필드로 정의 | ||
| - 생성자를 통한 데이터 초기화 | ||
| - 학생 정보를 출력하는 메서드 포함 | ||
|
|
||
| ### 2. `java-basic/Main.java` | ||
| - **역할**: 프로그램 실행 | ||
| - **주요 내용**: | ||
| - `Student` 클래스의 인스턴스(객체) 생성 | ||
| - 생성된 객체의 메서드를 호출하여 콘솔에 데이터 출력 및 확인 | ||
|
|
||
| ## 🤔 느낀 점 / 어려웠던 점 | ||
| -java 문법을 되새기는 시간을 가지게 된것 같습니다. | ||
| -객체 지향 부분을 더욱 심도있게 학습해야할것 같습니다. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package model; | ||
|
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.
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. model은 class를 넣어둔다고 생각해서 model 폴더에 넣어두었습니다. 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. 패키지 구조는 추후 TDD 또는 DDD 설계에 사용될 개념이기 때문에 미리 학습하시고 넘어가면 좋을 것 같습니다. |
||
|
|
||
| public class Student{ | ||
| private String name; | ||
| private String studentId; | ||
| private String major; | ||
|
Comment on lines
+4
to
+6
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. 객체의 정보를 저장하는 필드네요! private로 작성하여 외부에서 접근이 불가능하게 하신 점 정말 잘 하신 것 같습니다. 또한 studentId를 String으로 선언하신 이유가 있을까요? Id 경우 정수형으로 선언해도 될텐데 String으로 선언하신 이유가 궁금하네요!
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. 외부에서 접근을 막아 무결성을 유지하기 위해서 라고 생각합니다.
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. studentId를 String으로 한 이유는 만약 0으로 시작 할 경우 int로 하면 0이 손실되기 떄문에 데이터를 보존할려고 String을 사용했습니다. 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. private 경우 OOP 원칙과 연관지어서 공부하시면 더 개념이 풍부해지실 것 같습니다. 상속과 캡슐화 관점에서 private 사용 이유를 고민해보시면 좋을 것 같아요 |
||
|
|
||
|
|
||
| public Student(String name,String studentId,String major){ | ||
| this.name = name; | ||
| this.studentId = studentId; | ||
| this. major = major; | ||
| } | ||
| // 출력 메소드 | ||
| public static void printAll(Student[] students){ | ||
| for(Student student : students){ | ||
| System.out.printf("이름:%s 학번:%s 전공:%s\n",student.name,student.studentId,student.major); | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
+14
to
+20
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. 이름 학번 전공을 순차적으로 출력하는 함수로 출력 기능을 담당하고 있네요
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. main클래스에 최소한 코드만 두고 싶어 student 클래스에 넣어두었습니다. |
||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
로직을 깔끔하게 잘 작성하신 것 같습니다!
해당 로직이 Main 클래스에 있다는 점에 대해 한번 생각해보시면 좋을 것 같습니다.
Main 클래스의 역할은 뭘까요? 민구님의 의견 편하게 말씀해주세요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main에는 최소한의 코드가 있어야하고 실행을 담당하는 클래스라고 생각하고 있습니다.
레이어드 아키텍처 학습 후에 더욱 구조화 해보도록 하겠습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
실행을 담당하는 클래스를 따로 두고 (예를 들어 run class나 메서드) main 클래스는 해당 실행 메서드를 호출하는 역할로 작성한다면 민구님이 설계하신 "main 클래스는 최소한의 코드가 있어야 한다" 라는 부분을 더 강조할 수 있을 것 같습니다.
구현 방법에 대해 다양하게 고민해보시면 좋을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://wikidocs.net/160947
해당 사이트의 SbbApplication.java 클래스 코드를 보시면 이해가 좀 더 쉬울 것 같아서 보내드립니다😊