[Java] 객체 지향 연습 문제

2024. 8. 13. 22:46Java/객체지향

1. 다음과 같은 실행 결과를 얻도록 Student 클래스에 생성자와 info()를 추가하시오.

public class Ex5_1 {
  public static void main(String[] args) {
    Student s = new Student ("홍길동", 1, 1, 100, 60 , 76);
    
    String str = s.info();
    System.out.println(str);
  }

}

//홍길동, 1, 1, 100, 60, 76, 236, 78.7

 

 

2. getTotal()과 getAverage()를 추가하시오. 

public class Ex5_2 {
  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());
    System.out.println("평균: " + s.getAverage());
  }
}

 

'Java > 객체지향' 카테고리의 다른 글

[Java] 인터페이스  (0) 2024.08.15
[Java] 상속 2  (0) 2024.08.14
[Java] 객체 지향 연습 정답  (0) 2024.08.13
[Java] 객체 지향 - 3  (0) 2024.08.09
[Java] 객체 지향 - 1  (0) 2024.08.05