자바/자바의정석-연습문제
자바의정석 연습문제 풀이 6장 6-5
김발자~
2022. 9. 22. 20:49
반응형
자바의 정석 3판 연습문제 풀이
연습문제 파일은 아래 링크에서 다운받을 수 있다
GitHub - castello/javajungsuk3: soure codes and ppt files of javajungsuk 3rd edition
soure codes and ppt files of javajungsuk 3rd edition - GitHub - castello/javajungsuk3: soure codes and ppt files of javajungsuk 3rd edition
github.com
http://www.yes24.com/Product/Goods/24259565
Java의 정석 - YES24
최근 7년동안 자바 분야의 베스트 셀러 1위를 지켜온 `자바의 정석`의 최신판. 저자가 카페에서 12년간 직접 독자들에게 답변을 해오면서 초보자가 어려워하는 부분을 잘 파악하고 쓴 책. 뿐만 아
www.yes24.com
자바의 정석 저자 남궁성 님이 직접 올려주신 문제다
챕터6은 총 24문제로 구성되어 있다
6-5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
public class Practice_6_3_4_5 {
public static void main(String[] args) {
Student s = new Student("홍길동", 1, 1, 100, 60, 76);
System.out.println(s.info());
}
}
class Student{
String name;
int ban;
int no;
int kor;
int eng;
int math;
Student(String name, int ban, int no, int kor, int eng, int math){
this.name = name;
this.ban = ban;
this.no = no;
this.kor = kor;
this.eng = eng;
this.math = math;
}
int gotTotal() {
return kor+eng+math;
}
float getAverage() {
return (int)((kor+eng+math)/3f*10+0.5)/10f;
}
String info() {
return name + ","+ ban+"," + no + "," + kor + "," + eng+"," + math + "," + gotTotal() + "," + getAverage() ;
}
}
|
cs |
6-4에서 메인 메소드 안에 있던 것들을 빼고, student 생성자와 info 메서드를 선언해주면 된다
생성자 Student에서 this 매개변수를 활용해 iv와 lv를 따로 지정해주는 것에 주의
반응형