| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 티스토리 초대장
- 프레시업 #풀무원 #하루한병 #건강만들기 #풀무원 녹즙
- Emmet
- GitHub Mirroring
- gitlab 연동
- 네이버 클라우드 플랫폼
- 초대장
- '티스토리 초대장/ 티스토리초대'
- 실행시간 측정
- 티스토리 초대장/ 티스토리초대
- GitLab Mirroring
- code 설치
- 티스토리초대
- Path Alias
- eslint-import-resolver-typescript
- GitLab미러링
- 니돈내먹
- visual studio code cli
- visual studio code
- 음료같은녹즙
- GitHub 미러링
- code 세팅
- code .
- settings sync
- webstorm
- react native #gradle
- currentTimeMillis
- 프리티어
- 유니옥션
- React Native
Archives
- Today
- Total
방치하기
과제 주석 달기 , 그리고 다이어 그램 하고 메모리 본문
반응형
class Product
{
int price; // 제품의 가격
int bonusPoint; // 제품구매 시 제공하는 보너스점수
Product(int price) {
this.price = price;
bonusPoint =(int)(price/10.0); // 보너스점수는 제품가격의 10%
}
}
class Tv extends Product {
Tv() {
// 조상클래스의 생성자 Product(int price)를 호출한다.
super(100); // Tv의 가격을 100만원으로 한다.
}
public String toString() { // Object클래스의 toString()을 오버라이딩한다.
return "Tv";
}
}
class Computer extends Product {
Computer() {
super(200);
}
public String toString() {
return "Computer";
}
}
class Buyer { // 고객, 물건을 사는 사람
int money = 1000; // 소유금액
int bonusPoint = 0; // 보너스점수
void buy(Product p) {
if(money < p.price) {
System.out.println("잔액이 부족하여 물건을 살수 없습니다.");
return;
}
money -= p.price; // 가진 돈에서 구입한 제품의 가격을 뺀다.
bonusPoint += p.bonusPoint; // 제품의 보너스 점수를 추가한다.
System.out.println(p + "을/를 구입하셨습니다.");
}
}
class PolyArgumentTest {
public static void main(String args[]) {
Buyer b = new Buyer();
Tv tv = new Tv();
Computer com = new Computer();
b.buy(tv);
b.buy(com);
System.out.println("현재 남은 돈은 " + b.money + "만원입니다.");
System.out.println("현재 보너스점수는 " + b.bonusPoint + "점입니다.");
}
}
반응형
Comments