StdList
package arrayListEx;
// 사진보고 다시 출력해보기
public class StdList {
String name;
int jums1;
int jums2;
int jums3;
// int[] jums=new int[3];
public StdList(String name, int jums1, int jums2, int jums3) {
this.name = name;
this.jums1 = jums1;
this.jums2 = jums2;
this.jums3 = jums3;
}
public String getName() {
return name;
}
public int getJums1() {
return jums1;
}
public int getJums2() {
return jums2;
}
public int getJums3() {
return jums3;
}
public String toString() {
return name + " 합계 : " + (jums1+jums2+jums3);
}
}
//public String toString() {
// for(int i=0; i<jums.length;i++) {
// return name + jums[i] + "합계 :";
// public StdList(String name, int[] jums) {
// this.name = name;
// this.jums = new int[3];
// this.jums = score1;
// }
//
// public String getName() {
// return name;
// }
//
// public int[] getJums() {
// return jums;
// }
// public int avg() {
// int i, sum;
// for (i = 0, sum=0; i < jums.length; i++)
// sum +=jums[i];
// return sum / 3;
// }
StdListScore - main method
package arrayListEx;
//사진보고 다시 출력해보기
import java.util.ArrayList;
public class StdListScore {
public static void main(String[] args) {
ArrayList<StdList> data = new ArrayList<>();
// (new StdList("이희연", 65,90,100));은 객체 생성코드
// 나머지 설명은 jums코드 참고하기
//
// int[] score1 = { 90, 30, 50 };
// int[] score2 = { 50, 80, 50 };
// int[] score3 = { 90, 60, 50 };
data.add(new StdList("이희연", 90, 30, 50));
data.add(new StdList("황의조", 50, 80, 50));
data.add(new StdList("손흥민", 90, 60, 50));
for (StdList k : data)
System.out.println(k);// (k) == (k.toString()) 같은 코드임
}
}