일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- border-box
- #android activity
- #자바상속#자바이즈어#is~a
- html multimedia
- mac terminal command
- #binary
- html code
- #성적관리프로그램
- #1차원배열
- #다차원포인터
- #C++ has~a
- 하이퍼레저패브릭
- 토큰경제
- relative path
- html5 new tag
- html youtube
- html id
- #bubbleSort
- html plug-in
- #C++ 연산자함수오버로딩
- hyperledger transaction
- #JAVASCRIPT
- #CallByAddress
- git flow
- html charset
- docker example
- #2차원배열
- html object
- #3차원배열
- html video
- Today
- Total
A sentimental robot
Object-oriented style score management 본문
import java.util.Scanner;
public class Hello2 {
int[] score;
float avg;
String name;
public Hello2() { // 생성자에서 필드 초기화
score = new int[4];
}
public void setName(String a) {
name = a;
}
public void setKor(int k) {
score[0] = k;
}
public void setEng(int e) {
score[1] = e;
}
public void setMat(int m) {
score[2] = m;
}
public String getName() {
return name;
}
public int getKor() {
return score[0];
}
public int getEng() {
return score[1];
}
public int getMat() {
return score[2];
}
public int getTotal() {
return score[3] = score[0] + score[1] + score[2];
}
public float getAvg() {
return avg = score[3] / 3.f;
}
public static void main(String[] ar) {
Scanner sc = new Scanner(System.in);
int student;
System.out.print("The number of student : ");
student = sc.nextInt();
Hello2[] ss = new Hello2[student]; // 학생 수만큼 객체배열 참조변수 만들기
for (int i = 0; i < ss.length ; i++) // 객체만들기
ss[i] = new Hello2();
for (int i = 0; i < ss.length ; i++) {
System.out.print("name input : ");
ss[i].setName(sc.next());
System.out.print("kor input : ");
ss[i].setKor(sc.nextInt());
System.out.print("eng input : ");
ss[i].setEng(sc.nextInt());
System.out.print("mat input : ");
ss[i].setMat(sc.nextInt());
}
// print ALL
for (int i = 0; i < ss.length ; i++) {
System.out.print(ss[i].getName() + " \t");
System.out.print(ss[i].getKor() + " \t");
System.out.print(ss[i].getEng() + " \t");
System.out.print(ss[i].getMat() + " \t");
System.out.print(ss[i].getTotal() + " \t");
System.out.println(ss[i].getAvg() + " \t");
}
}
}
'Java' 카테고리의 다른 글
This (0) | 2017.12.28 |
---|---|
Object oriented style exercise (0) | 2017.12.28 |
The elements of "Class" (0) | 2017.12.28 |
Score Management[Three dimensional] (0) | 2017.12.28 |
Score Management[Two dimensional] (0) | 2017.12.28 |