File tree Expand file tree Collapse file tree 3 files changed +123
-0
lines changed
memory/repository/computer_programming_2/src/lab02/shoolGrade Expand file tree Collapse file tree 3 files changed +123
-0
lines changed Original file line number Diff line number Diff line change 1+ package lab02 .shoolGrade ;
2+
3+ class ClassRoom {
4+
5+ private Student [] students ;
6+
7+ ClassRoom (Student [] students ) {
8+ this .students = students ;
9+ }
10+
11+ void printAllStudents () {
12+ System .out .println ("=== 전체 학생 정보 ===" );
13+ for (Student s : students ) {
14+ s .printInfo ();
15+ }
16+ }
17+
18+ double getAverage () {
19+ int sum = 0 ;
20+ for (Student s : students ) {
21+ sum += s .getScore ();
22+ }
23+ return (double ) sum / students .length ;
24+ }
25+
26+ Student getTopStudent () {
27+ Student top = students [0 ];
28+ for (Student s : students ) {
29+ if (s .getScore () > top .getScore ()) {
30+ top = s ;
31+ }
32+ }
33+ return top ;
34+ }
35+
36+ Student getLowestStudent () {
37+ Student low = students [0 ];
38+ for (Student s : students ) {
39+ if (s .getScore () < low .getScore ()) {
40+ low = s ;
41+ }
42+ }
43+ return low ;
44+ }
45+
46+ void printPassStudents () {
47+ System .out .println ("=== 합격자 명단 ===" );
48+ for (Student s : students ) {
49+ if (s .isPass ()) {
50+ System .out .println (s .getName () + " (점수: " + s .getScore () + ")" );
51+ }
52+ }
53+ }
54+ }
Original file line number Diff line number Diff line change 1+ package lab02 .shoolGrade ;
2+
3+ class Student {
4+ private String name ;
5+ private int score ;
6+ private String grade ;
7+
8+ public Student (String name , int score ) {
9+ this .name = name ;
10+ this .score = score ;
11+ this .grade = calculateGrade (score );
12+ }
13+
14+ private String calculateGrade (int score ) {
15+ if (score >= 90 ) {
16+ return "A" ;
17+ } else if (score >= 80 ) {
18+ return "B" ;
19+ } else if (score >= 70 ) {
20+ return "C" ;
21+ } else if (score >= 60 ) {
22+ return "D" ;
23+ } else {
24+ return "F" ;
25+ }
26+ }
27+
28+ public void printInfo () {
29+ System .out .println (name + " - 점수: " + score + ", 학점: " + grade );
30+ }
31+
32+ public boolean isPass () {
33+ return score >= 60 ;
34+ }
35+
36+ public String getName () {
37+ return name ;
38+ }
39+
40+ public int getScore () {
41+ return score ;
42+ }
43+ }
Original file line number Diff line number Diff line change 1+ package lab02 .shoolGrade ;
2+
3+ public class StudentMain {
4+ public static void main (String [] args ) {
5+ Student [] students = {
6+ new Student ("철수" , 95 ),
7+ new Student ("영희" , 82 ),
8+ new Student ("민수" , 67 ),
9+ new Student ("지현" , 58 ),
10+ new Student ("호준" , 74 )
11+ };
12+
13+ ClassRoom classRoom = new ClassRoom (students );
14+
15+ classRoom .printAllStudents ();
16+ System .out .println ("평균 점수: " + classRoom .getAverage ());
17+
18+ Student top = classRoom .getTopStudent ();
19+ System .out .println ("최고 점수 학생: " + top .getName () + " (" + top .getScore () + "점)" );
20+
21+ Student low = classRoom .getLowestStudent ();
22+ System .out .println ("최저 점수 학생: " + low .getName () + " (" + low .getScore () + "점)" );
23+
24+ classRoom .printPassStudents ();
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments