일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- html charset
- #1차원배열
- #2차원배열
- html id
- #3차원배열
- #자바상속#자바이즈어#is~a
- #CallByAddress
- html plug-in
- #다차원포인터
- html youtube
- docker example
- html code
- html object
- #성적관리프로그램
- hyperledger transaction
- html video
- git flow
- #C++ has~a
- mac terminal command
- html5 new tag
- 하이퍼레저패브릭
- #binary
- html multimedia
- #bubbleSort
- #C++ 연산자함수오버로딩
- 토큰경제
- #JAVASCRIPT
- #android activity
- border-box
- relative path
- Today
- Total
A sentimental robot
"Has~A" exercise 본문
Data Class 1
public class Name {
private String name;
public Name() {
}
public Name(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Data Class 2
public class Subject {
private int score;
public void setScore(int score) {
this.score=score;
}
public int getScore() {
return score;
}
}
Processing Class
import java.util.Scanner;
public class Management {
private Name name;
private Subject kor;
private Subject eng;
private Subject mat;
private int total;
private float avg;
public Management() {
name = new Name();
kor = new Subject();
eng = new Subject();
mat = new Subject();
total = 0;
avg = 0;
}
public void setName(String name) {
this.name.setName(name);
}
public void setKor(int kor) {
this.kor.setScore(kor);
}
public void setEng(int eng) {
this.eng.setScore(eng);
}
public void setMat(int mat) {
this.mat.setScore(mat);
}
public String getName() {
return name.getName();
}
public int getKor() {
return kor.getScore();
}
public int getEng() {
return eng.getScore();
}
public int getMat() {
return mat.getScore();
}
public void setTotal() {
this.total = kor.getScore() + eng.getScore() + mat.getScore();
}
public int getTotal() {
return total;
}
public void setAvg() {
this.avg = total / 3.f;
}
public float getAvg() {
return avg;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Management ss = new Management();
System.out.print("name input :");
ss.setName(sc.next());
System.out.print("kor :");
ss.setKor(sc.nextInt());
System.out.print("eng :");
ss.setEng(sc.nextInt());
System.out.print("mat :");
ss.setMat(sc.nextInt());
ss.setTotal();
System.out.println(ss.getName());
System.out.println(ss.getKor());
System.out.println(ss.getEng());
System.out.println(ss.getMat());
System.out.println(ss.getTotal());
System.out.println(ss.getAvg());
}
}
'Java' 카테고리의 다른 글
Is~a 상속관계 (0) | 2017.12.29 |
---|---|
Extended.ver (0) | 2017.12.28 |
Has~a (0) | 2017.12.28 |
This (0) | 2017.12.28 |
Object oriented style exercise (0) | 2017.12.28 |