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