객체 설계 도전과제
1. 김길동이가 용돈을 오만원 가지고 있습니다.
2. 놋데 백화점에 컴퓨터가 있습니다. 만원입니다.
3. 놋데 백화점에 카메라가 있습니다. 만오천원입니다.
4. 길거리에 사과가 있습니다. 천원입니다.
5. 길거리에도 카메라가 있습니다. 만천원입니다.
6. 김길동이가 백화점에서 컴퓨터와 카메라를 구매했습니다.
7. 김길동이가 길거리에서 사과와 카메라를 구매했습니다.
8. 김길동이가 백화점에서 구매한 컴퓨터를 환불했습니다.
9. 김길동이가 백화점에서 구매한 카메라를 환불했습니다.
현재 구매는 김길동이의 용돈이 다 소모가 되도 구매가 진행됩니다. 이를 변경해서, 물품의 금액만큼 용돈이 있을때만 구매가
진행되도록 구매 메서드를 변경합니다.
10. 놋데 백화점에 청바지가 있습니다. 이만원입니다.
11. 놋데 백화점에 청치마가 있습니다. 이만오천원입니다.
12. 김길동이가 청바지를 구매했습니다.
13. 김길동이가 청바지를 청치마로 교완했습니다.
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | package mypackage; import mypackage.Notte.Camera; import mypackage.Notte.Computer; import mypackage.Notte.Jeans; import mypackage.Notte.JeansChima; import mypackage.Street.Apple; import mypackage.Street.StreetCamera; public class Variables { public static void main(String[] args) { Kimgildong k = new Kimgildong(); Notte notte = new Notte(); Street st = new Street(); k.buyCoumpter(notte.c); k.displayMoney(); k.buyCamera(notte.cm); k.displayMoney(); k.buyStreetApple(st.apple); k.displayMoney(); k.buyStreetCamera(st.sc); k.displayMoney(); k.refundCoumpter(notte.c); k.displayMoney(); k.refundCamera(notte.cm); k.displayMoney(); k.buyJeans(notte.j); k.displayMoney(); k.refundJeans(notte.j); k.displayMoney(); k.exchange(notte.j, notte.jm); k.displayMoney(); } } class Kimgildong{ Kimgildong(){} int money = 50000; void displayMoney(){ System.out.println("현재 가진돈은 : "+money+"원"); } void buyCoumpter(Computer c){ if(money >= c.price){ money = money - c.price; } } void buyCamera(Camera cm){ if(money >= cm.price){ money = money - cm.price; } } void buyStreetApple(Apple apple){ if(money >= apple.price){ money = money - apple.price; } } void buyStreetCamera(StreetCamera st){ if(money >= st.price){ money = money - st.price; } } void refundCoumpter(Computer c){ if(money >= c.price){ money = money + c.price; } } void refundCamera(Camera cm){ if(money >= cm.price){ money = money + cm.price; } } void buyJeans(Jeans j){ if(money >= j.price){ money = money - j.price; } } void refundJeans(Jeans j){ if(money >= j.price){ money = money + j.price; } } void exchange(Jeans j, JeansChima jm){ if(money >= jm.price){ money = money + j.price; money = money - jm.price; } } } class Notte{//백화점 Notte(){} Computer c = new Computer(); Camera cm = new Camera(); Jeans j = new Jeans(); JeansChima jm = new JeansChima(); class Computer{//컴퓨터 int price = 10000; } class Camera{//카메라 int price = 15000; } class Jeans{//청바지 int price = 20000; } class JeansChima{//청치마 int price = 25000; } } class Street{//길거리 Street(){} Apple apple = new Apple(); StreetCamera sc = new StreetCamera(); class Apple{//사과 int price = 1000; } class StreetCamera{//거리 카메라 int price = 11000; } } | cs |
'개발' 카테고리의 다른 글
[java] 1부터 50개의 숫자 중에서 25를 골라서 5행 5열에 출력 (0) | 2013.04.15 |
---|---|
[java] 지비 모터스 자동차 판매 매출 (0) | 2013.04.05 |
[java] 지비 백화점 매출 (0) | 2013.04.05 |
[java] 사과를 구매한 홍길동의 돈과 지갑의 돈 확인 (0) | 2013.04.05 |
[java] Instance VS static (0) | 2013.04.05 |