패키지명 : com.kosta.sample.quiz1
다음과 같은 정보를 관리하는 Sukang 클래스가 있다.
이름 국어 영어 수학
------- ----- ----- -----
홍길동 100 90 80
아무개 88 77 66
###########################################################################
1. Sukang 클래스에 국어,영어,수학 점수를 담을 수 있는 빈 배열 변수 scores를 생성하세오.
배열 변수 scores : 인스턴스 변수(접근제어자 private)
생성자 : 기본생성자
2. Sukang 클래스의 부모 클래스 Score를 생성하시오.
생성자1 : "국어 영어 수학"이라는 타이틀을 출력하는 함수
실행결과) 국어 영어 수학
생성자2 : 국어,영어,수학 점수를 매개변수로 받아 출력하는 함수
(생성자1 함수를 사용할 것)
실행결과) 국어 영어 수학
100 90 80
국어 영어 수학
88 77 66
3. Score 클래스에 각 과목의 "과목명 평균점수"를 계산해서 리턴해주는 subjectAverage() 함수를 생성하세요.
4. Score 클래스에 전체 응시인원수를 리턴해주는 userCount() 함수를 생성하세요.
5. Sukang 클래스에서 subjectAverage() 함수를 재사용해 사용자 이름도 같이 출력되는 함수를 생성하세요.
main.class
public class test{
public static void main(String[] args){
Sukang clsArr = {new Sukang(100,90,80), new Sukang(90,85,85)};
String str = Score.subjectSum(clsArr);
System.out.println(clsArr);
}
}
Sukang.class
class Sukang{
private int ckor;
private int ceng;
private int cmath;
Sukang(int k, int e, int m){
this.ckor = k;
this.ceng = e;
this.cmath = m;
}
public int getKor(){
return ckor;
}
public int getEng(){
return ceng;
}
public int getMath(){
return cmath;
}
}
Score.class
class Score{
Score(){
System.out.println("국어\t 영어\t 수학\t");
}
Score(int k, int e, int m){
System.out.println(k+"\t"+e+"\t"+m+"\t");
}
public static String subjectSum(Sukang[] sArr){
int ksum=0, esum=0, msum=0;
for(int i=0;i<sArr.length;i++){
ksum += sArr[i].getKor();
esum += sArr[i].getEng();
msum += sArr[i].getMath();
}
String msg = "국어: "+ksum+"영어: "+esum+"수학: "+msum;
return msg;
}
}
'KOSTA : 클라우드 네이티브 애플리케이션 개발 전문가 양성과정' 카테고리의 다른 글
05/09 21일차 컬렉션 (0) | 2024.05.10 |
---|---|
05/09 20일차 제어자(static,final,abstract) ,인터페이스 (0) | 2024.05.09 |
05/08 19일차 Java 문법 Test (0) | 2024.05.08 |
05/07 18일차 객체지향언어II : 예외처리 (0) | 2024.05.07 |
05/07 18일차 객체지향언어II : super(), package와 import (0) | 2024.05.07 |