| sametim |
코드 낭비일지도 모르지만.. 저로서는 이거말고는 되지가 않네요. 무능력해 죄송합니다.
public class Box01 {
int boxId, amount=0;
String width, length, height;
Box01(int boxId, String width, String length, String height) {
this.boxId = boxId;
this.width = width;
this.length = length;
this.height = height;
amount ++;
}
Box01(int boxId, String width, String length, String height, Box01 obj) {
this.boxId = boxId;
this.width = width;
this.length = length;
this.height = height;
this.amount = obj.amount + 1;
}
}
===============================================
public class Box01Test {
int amount=0;
public static void main(String args[]) {
Box01 obj1, obj2, obj3, obj4;
obj1 = new Box01(1, "1", "2", "3");
obj2 = new Box01(2, "4", "5", "6", obj1);
obj3 = new Box01(3, "7", "8", "9", obj2);
obj4 = new Box01(4, "10", "11", "12", obj3);
printBox01(obj1);
printBox01(obj2);
printBox01(obj3);
printBox01(obj4);
}
static void printBox01(Box01 obj) {
System.out.println("Box"+obj.boxId+"번의 id 번호 : " + obj.boxId);
System.out.println("box의 개수 : "+ obj.amount);
}
} |
2014/12/19 |
|