5강 이것만은 알고갑시다 1번 질문
2014-05-26
|
by asking
1382
5강 이것만은 알고갑시다 문제 1번 질문입니다.
아래와 같이 코딩을 하였습니다.
class GoodsInfo {
String Goodscode, Goodsname, Maker;
int Price;
double Discount;
GoodsInfo(String Goodscode, String Goodsname, String Maker, int Price, double Discount) {
this.Goodscode = Goodscode;
this.Goodsname = Goodsname;
this.Maker = Maker;
this.Price = Price;
this.Discount = Discount;
}
GoodsInfo(String Goodscode, String Goodsname, String Maker, int Pirce) {
this.Goodscode = Goodscode;
this.Goodsname = Goodsname;
this.Maker = Maker;
this.Price = Price;
}
void ChangeDiscount(double Discount) {
this.Discount = Discount;
}
int CalSPrice() {
return Price - (int) (Price * Discount);
}
}
class GoodsInfoEx {
public static void main(String args[]) {
GoodsInfo obj = new GoodsInfo("12345", "mirror", "samsung", 2000, 0.2);
GoodsInfo obj2 = new GoodsInfo("13567", "paper", "lg", 100);
PrintGoodsInfo(obj);
PrintGoodsInfo(obj2);
}
static void PrintGoodsInfo(GoodsInfo obj) {
System.out.println("상품코드 = " + obj.Goodscode);
System.out.println("상품명 = " + obj.Goodsname);
System.out.println("상품브랜드 = " + obj.Maker);
System.out.println("상품가격 = " + obj.Price);
System.out.println("할인율 = " + obj.Discount);
System.out.println("판매가격 = " + obj.CalSPrice());
System.out.println();
}
}
결과 출력값이 파라미터 5개 넣은 것은 잘 나오는데, 파라미터 4개짜리를 넣은것은 상품가격이 0으로 나옵니다.
즉, 할인율을 기입하지 않은 생성자로 만든 객체는 잘 집어넣어준 상품가격도 값이 없는 것처럼 나오게 됩니다.
(나머지 상품코드, 상품명, 상품브랜드 까지는 넣어준대로 잘 나오는데 상품가격만 집어넣어준 값 대신 0으로 출력됩니다)
뭐가 잘못된 것일까요? 답변 요청드립니다.