일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- #C++ 연산자함수오버로딩
- hyperledger transaction
- #3차원배열
- #자바상속#자바이즈어#is~a
- docker example
- border-box
- html5 new tag
- #JAVASCRIPT
- html object
- #C++ has~a
- html plug-in
- #다차원포인터
- #binary
- #2차원배열
- #bubbleSort
- html charset
- #CallByAddress
- relative path
- 하이퍼레저패브릭
- #1차원배열
- git flow
- #성적관리프로그램
- html code
- #android activity
- 토큰경제
- html multimedia
- html id
- html youtube
- html video
- mac terminal command
Archives
- Today
- Total
A sentimental robot
다시 한번 Has~a 본문
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
32
33
34
35
36
37 |
import java.util.Scanner;
public class Day10_03 {
public static void main(String[] args) {
Cl[] cl;
int n1;
int n2;
System.out.println("=== Score Management ===");
Scanner sc = new Scanner(System.in);
System.out.println("몇 반을 입력할까요? : ");
n1 = sc.nextInt();
cl = new Cl[n1];
for (int i = 0; i < n1; i++) {
System.out.println(i + 1 + "반 학생 수를 입력하세요 :");
n2 = sc.nextInt();
cl[i] = new Cl(n2);
cl[i].setData();
}
// display
for(int i=0 ; i< n1; i++) {
System.out.println("--- "+(i+1)+"반 ---");
cl[i].getData();
}
}
}
|
cs |
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 |
import java.util.Scanner;
class Cl {
private Name[] name;
private Score[][] score;
private int[] sum;
private float[] avg;
public Cl(int num) {
name = new Name[num];
score = new Score[num][3];
sum = new int[num];
avg = new float[num];
for (int i = 0; i < name.length; i++) {
name[i] = new Name();
for(int j=0; j<score[i].length; j++) {
score[i][j]=new Score();
}
sum[i] = 0;
avg[i] = 0;
}
}
public void setData() {
Scanner sc = new Scanner(System.in);
for (int i = 0; i < name.length; i++) {
System.out.println(i + 1 + "번째 학생 이름을 입력하세요:");
name[i].setName(sc.next());
for (int j = 0; j < score[i].length; j++) {
System.out.println(i + 1 + "번째 학생 점수(국,영,수)를 입력하세요");
score[i][j].setScore(sc.nextInt());
sum[i] += score[i][j].getScore();
}
avg[i] = sum[i] / 3.f;
}
}
public void getData() {
for (int i = 0; i < name.length; i++) {
System.out.println("이름 :"+name[i].getName());
for (int j = 0; j < score[i].length; j++) {
System.out.println("국영수 점수 :"+score[i][j].getScore());
}
System.out.println("총점 :"+sum[i]);
System.out.println("평균 :"+avg[i]);
}
}
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 |
class Name {
private String name;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 |
class Score {
private int score;
public void setScore(int score) {
this.score = score;
}
public int getScore() {
return score;
}
}
|
cs |
'Java' 카테고리의 다른 글
Multi Chatting (0) | 2018.09.07 |
---|---|
1:1 채팅 (0) | 2018.09.06 |
NullPointerException (0) | 2018.06.30 |
Platform.runLater( ) (0) | 2018.02.07 |
Chatting UI (0) | 2018.02.07 |