Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- parcel
- degit
- 상속
- 왕초보
- Spring
- React
- 게시판
- 오버라이드
- git
- Spinner
- SQL
- Android
- java#왕초보
- 미니게임
- 스프링
- 코틀린
- 시큐어코딩
- 스타일보험
- java
- snowpack
- 함수
- 안드로이드
- 답글
- 숫자
- sub query
- 버전일치
- webpack
- kotlin
- FIle
- 쿠키
Archives
- Today
- Total
YSHUSH
Class 예제 본문
public class MainClass {
public static void main(String[] args) {
Student s = new Student();
s.name = "홍길동";
s.ban = 1;
s.no = 1;
s.kor = 100;
s.eng = 60;
s.math = 76;
System.out.println("이름:"+s.name);
System.out.println("총점:"+s.getTotal(s.kor, s.eng, s.math) );
System.out.println("평균:"+s.getAverage( ) );
}
}
class Student {
String name;
int ban;
int no;
int kor, eng, math;
------------------------------------------------------------------------------------------
// ↓이부분부터 채우기↓
// int total;
// 1번.
/*
int getTotal(int kor, int eng, int math) {
total = kor + eng + math;
return total;
}
double getAverage() {
return (double)total/3;
*/
// 2번.
int getTotal(int kor, int eng, int math) {
this.kor = kor;
this.eng = eng;
this.math = math;
return (kor + eng + math);
}
double getAverage() {
return (double)(kor + eng + math) / 3;
------------------------------------------------------------------------------------------
}
}
'Coding > Java' 카테고리의 다른 글
Encapsule (0) | 2021.12.14 |
---|---|
Encapsulation (0) | 2021.12.14 |
Constructor (0) | 2021.12.14 |
OOP(Object Oriented Programing) (0) | 2021.12.14 |
File writer (0) | 2021.12.14 |