일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 로또
- 전체텍스트
- 다운캐스팅
- 자바
- 가변인자
- while
- Random
- 상속
- 이클립스
- IBatis procedure
- 추상클래스
- 다형성
- Validations
- jquery
- 스프링
- full text indexing
- 업캐스팅
- 전체
- 야구게임
- 상속예제
- Login with OAuth Authentication
- 단축키
- angular2
- 자바 야구게임
- 전자정부
- 형변환
- 25가지 효율적인 sql작성법
- 페이징
- Full text
Archives
- Today
- Total
nalaolla
Method 예제 5 본문
728x90
반응형
- package test.com;
- public class Test04Score {
- int num;
- String name;
- int kor;
- int eng;
- int math;
- int total;
- double avg;
- String grade;
- public void test() {
- name = "KIM";
- kor = 77;
- eng = 88;
- math = 99;
- total = kor + eng + math;
- avg = total / 3.0;
- if (avg >= 90) {
- grade = "A";
- } else if(avg >= 80) {
- grade = "B";
- } else if(avg >= 70) {
- grade = "C";
- } else if(avg >= 60) {
- grade = "D";
- } else {
- grade = "Other";
- }
- System.out.println(name);
- System.out.println(kor);
- System.out.println(eng);
- System.out.println(math);
- System.out.println(total);
- System.out.println(avg);
- if (avg >= 90) {
- grade = "A";
- } else if(avg >= 80) {
- grade = "B";
- } else if(avg >= 70) {
- grade = "C";
- } else if(avg >= 60) {
- grade = "D";
- } else {
- grade = "Other";
- }
- System.out.println(grade);
- System.out.println();
- }
- public void test2(String name, int kor, int eng, int math) {
- total = kor + eng + math;
- avg = total / 3.0;
- System.out.println(name);
- System.out.println(kor);
- System.out.println(eng);
- System.out.println(math);
- System.out.println(total);
- System.out.println(avg);
- String gradeStr = getGrade(avg);
- System.out.println(gradeStr);
- }
- public String test3() {
- return num+":"+name+":"+kor+":"+eng+":"+math+":"+total+":"+avg+":"+grade;
- }
- public String[] test3_2() {
- String[] results = new String[]{String.valueOf(num), name, String.valueOf(kor), String.valueOf(eng), String.valueOf(math), String.valueOf(total),String.valueOf(avg), grade};
- return results;
- }
- public Test04Score test3_3() {
- Test04Score ts04 = new Test04Score();
- ts04.num = num;
- ts04.name = name;
- ts04.kor = kor;
- ts04.eng = eng;
- ts04.math = math;
- ts04.total = total;
- ts04.avg = avg;
- ts04.grade = grade;
- return ts04;
- // return this; // --> 현재 클래스와 리턴클래스가 같은 타입인 경우 this리턴 처리가능
- }
- private String getGrade(double avg) {
- grade = "";
- if (avg >= 90) {
- grade = "A";
- } else if(avg >= 80) {
- grade = "B";
- } else if(avg >= 70) {
- grade = "C";
- } else if(avg >= 60) {
- grade = "D";
- } else {
- grade = "Other";
- }
- return grade;
- }
- }
- package test.com;
- public class Test04ScoreMain {
- public static void main(String[] args) {
- System.out.println("Score...");
- //Test04Score 클래스에 메소드를 만들어서 성적처리하는 프로그램을 완성하시오..
- //Method Name : Test
- Test04Score ts = new Test04Score();
- ts.test();
- ts.test2("김덕중", 90, 95, 90);
- System.out.println("====================");
- String result = ts.test3();
- System.out.println(result);
- String[] results = ts.test3_2();
- System.out.println(results.length);
- for (int i = 0; i < results.length; i++) {
- System.out.print(results[i] + " ");
- }
- System.out.println();
- System.out.println("============= object =============");
- Test04Score score = ts.test3_3();
- System.out.println(score.name);
- System.out.println(score.kor);
- System.out.println(score.eng);
- System.out.println(score.math);
- System.out.println(score.total);
- System.out.println(score.avg);
- System.out.println(score.grade);
- }
- }
728x90
반응형
'JAVA > 8. Method1' 카테고리의 다른 글
Method 예제 4 (0) | 2016.06.22 |
---|---|
Method 예제 3 (활용예제) (0) | 2016.06.22 |
Method 예제 2 (Method 정리) (0) | 2016.06.22 |
Method 예제 1 (예외처리) (0) | 2016.06.22 |