[JAVA.11] ์ƒ์†(Inheritance)๐Ÿ‡

Kama_Codeยท2023๋…„ 7์›” 16์ผ
1

JAVA

๋ชฉ๋ก ๋ณด๊ธฐ
16/20
post-thumbnail
post-custom-banner
  • ๊ฐ์ฒด์ง€ํ–ฅ์˜ ๊ฝƒ์€ ๋ฐ”๋กœ ์žฌํ™œ์šฉ์ผ ๊ฒƒ์ด๋‹ค.
    ์ƒ์†์€ ๊ฐ์ฒด์ง€ํ–ฅ์˜ ์žฌํ™œ์šฉ์„ฑ์„ ๊ทน๋Œ€ํ™”์‹œํ‚จ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ๋ฒ•์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค.
    ํšจ์œจ์„ฑ์„ ์œ„ํ•œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ด๋ผ ์‚ฌ๊ณ ๋ ฅ์ด ํ•„์š”ํ•˜๋ฉฐ ์–ด๋ ค์šด ๋‚ด์šฉ์ด๊ธฐ๋„ ํ•˜๋‹ค.

<Step.1> ์ƒ์†(Inheritance)

  • ์ƒ์†(Inheritance)์ด๋ž€ ๋ฌผ๋ ค์ค€๋‹ค๋Š” ์˜๋ฏธ๊ฐ€ ์žˆ๋‹ค.
    ์–ด๋–ค ๊ฐ์ฒด๊ฐ€ ์žˆ์„ ๋•Œ ๊ทธ ๊ฐ์ฒด์˜ ๋ณ€์ˆ˜์™€ ๋ฉ”์†Œ๋“œ๋ฅผ
    ๋‹ค๋ฅธ ๊ฐ์ฒด๊ฐ€ ๋ฌผ๋ ค ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ๋งํ•œ๋‹ค.
  • ์—ฌ๊ธฐ์„œ Unit ํด๋ž˜์Šค๋Š” ๋ถ€๋ชจ๋ฅผ ๋œปํ•˜๊ณ  Marine Medic Firebat์€ ์ž์‹์„ ๋œปํ•œ๋‹ค.
  • ์ƒ์†์„ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„  extends๋ฅผ ๋ถ™์ธ๋‹ค.

<Step.2> ์ƒ์†๊ด€๊ณ„์— ์žˆ๋Š” ํด๋ž˜์Šค์˜ ๊ฐ์ฒด ์ƒ์„ฑ

๋ถ€๋ชจ ํด๋ž˜์Šค๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ ์œ„ํ•ด์„  ๋ถ€๋ชจ ํด๋ž˜์Šค์˜ ์ƒ์„ฑ์ž๊ฐ€ ์˜ค๋ฒ„๋ผ์ด๋”ฉ(์žฌ์ •์˜) ๋˜์–ด์•ผ ํ•œ๋‹ค
ใ„ดsuper()์„ ํ†ตํ•ด ์ƒ์†๊ด€๊ณ„์— ์žˆ๋Š” ๋ถ€๋ชจํด๋ž˜์Šค์˜ ์ƒ์„ฑ์ž๋ฅผ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋‹ค.

  • ์ƒ์† ๊ด€๊ณ„์—์„œ ์ž์‹ ํด๋ž˜์Šค์˜ ๋ณ€์ˆ˜ ์‚ฝ์ž…์‹œ ๋ฐ˜๋“œ์‹œ ๋ถ€๋ชจํด๋ž˜์Šค์˜ ์ƒ์„ฑ์ž๊ฐ€ ํ˜ธ์ถœ์ด ๋œ๋‹ค.

์ ‘๊ทผ์ง€์ •์ž์— ๋”ฐ๋ผ protected์™€ public์€ ์ƒ์† ๊ด€๊ณ„์—์„œ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‚˜
private์€ getter/setter์— ์˜ํ•œ ๊ฐ„์ ‘์ ‘๊ทผ ์™ธ์— ์ ‘๊ทผ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.

<Step.3> ์˜ค๋ฒ„๋ผ์ด๋”ฉ(Overriding)

  • ๋ถ€๋ชจ๊ฒƒ์„ ๋ฎ์–ด ์“ด๊ฒƒ, ์žฌ์ •์˜ ๋˜๋Š” ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ์„ ๋งํ•œ๋‹ค.
    ใ„ด๋ฉ”์†Œ๋“œ๋ฅผ ์ •์˜ํ•˜์—ฌ ๋ฎ์–ด์“ฐ๋Š” ๊ฒƒ์ด๋‹ค. ๋ฐ˜ํ™˜๊ฐ’์˜ ํ˜•๋„ ๊ฐ™์•„์•ผ๋งŒ ํ•œ๋‹ค.
    ใ„ด๋‹จ, final์€ ํด๋ž˜์Šค๋“  ๋ฉ”์†Œ๋“œ๋“  ๋ณ€์ˆ˜๋“  ์˜ค๋ฒ„๋ผ์ด๋”ฉ์„ ํ•  ์ˆ˜ ์—†๋‹ค.

โ˜… ์˜ค๋ฒ„๋ผ์ด๋”ฉ์˜ ๋ชฉ์ 
1. ๋ถ€๋ชจ ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ์˜ ๊ธฐ๋Šฅ ๋ณ€๊ฒฝ
2. ๋ถ€๋ชจ ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ์˜ ๊ธฐ๋Šฅ ์ถ”๊ฐ€

showState()๋Š” ์ž์‹ ํด๋ž˜์Šค์—์„œ ์˜ค๋ฒ„๋ผ์ด๋”ฉ๋˜์—ˆ๋‹ค. (๋ฐ”๊พผ ๊ฒƒ์ด๋‹ค)
์Šคํ”ผ์ปค์˜ ๋ณผ๋ฅจ์˜ ํฌ๊ธฐ๋ฅผ ๋ฒ ์ด์Šค์˜ ๋ณผ๋ฅจ์˜ ํฌ๊ธฐ๋กœ ๋ณ€๊ฒฝํ•œ ๊ฒƒ(์žฌ์ •์˜) => ์˜ค๋ฒ„๋ผ์ด๋”ฉ

  • ํด๋ž˜์Šค B๋Š” ๋ถ€๋ชจ ํด๋ž˜์Šค A๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•˜๊ณ 
    ํด๋ž˜์Šค C๋Š” ํด๋ž˜์ŠคB๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ–ˆ๋‹ค.
    ํด๋ž˜์Šค A B C๋ฅผ ์ถœ๋ ฅํ•˜๋ฉด ์ „์ฒด C ํด๋ž˜์Šค์˜ ์ถœ๋ ฅ๋ฌธ๋งŒ ๋‚˜์˜จ๋‹ค.
    โ˜… ์˜ค๋ฒ„๋ผ์ด๋”ฉ์œผ๋กœ ์ธํ•ด A์™€ B๊ฐ€ ๋ชจ๋‘ ๊ฐ€๋ ค์กŒ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค

<Step.4> ๊ฐ€๋ณ€์ธ์ž(Variable Arguments)

  • ์˜ค๋ฒ„๋กœ๋”ฉ์„ ๋Œ€์ฑ„ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ๋ฒ•์ด๋‹ค.
  • ๋ฉ”์†Œ๋“œ์˜ ์—ฌ๋Ÿฌ๊ฐ€์ง€์˜ ํ˜ธ์ถœ ํ˜•์‹์œผ๋กœ ๋Œ€์ฒดํ•  ์ˆ˜ ์žˆ๋‹ค.

ใ… public PrintStream printf(String format, Object ...args) { ... }
ใ„ด๋งค๊ฐœ๋ณ€์ˆ˜์˜ ๊ฐœ์ˆ˜๋ฅผ ๋™์ ์œผ๋กœ ์ง€์ •ํ•ด์ฃผ๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.
ใ„ด๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ๋ช‡๊ฐœ๊ฐ€ ์˜ฌ์ง€ ๋ชจ๋ฅด๋Š” ๋ณ€์ˆ˜๋กœ ๋‘”๋‹ค๋Š” ๋œป์ด๋‹ค.

ใ… ์‚ฌ์šฉ๋ฒ•(๊ทœ์น™):
1. ๊ฐ€๋ณ€์ธ์ž๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜ ์ค‘ ์ œ์ผ ๋งˆ์ง€๋ง‰์— ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค
ใ„ด๊ฐ€๋ณ€์ธ์ž๋ฅผ ์•ž์— ๋‘๋ฉด ๋ฉ”์†Œ๋“œ์—์„œ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๊ฐ€์ง€๊ณ  ์˜ฌ ๋•Œ
ใ„ด์–ด๋””๊นŒ์ง€๊ฐ€ ๊ฐ€๋ณ€์ธ์ž์ธ์ง€ ๊ตฌ๋ถ„์„ ํ•  ์ˆ˜ ์—†๊ฒŒ ๋˜๋ฏ€๋กœ ์˜ค๋ฅ˜ ๋ฐœ์ƒ
2. ๊ฐ™์€ ํ˜•์‹์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์กด์žฌํ•˜๋Š” ์˜ค๋ฒ„๋กœ๋”ฉ์—์„œ๋Š” ํ”ผํ•ด์•ผ ํ•œ๋‹ค
ใ„ดํ˜ธ์ถœํ•˜์—ฌ ์ „๋‹ฌํ•ด์ค„๋•Œ ์–ด๋–ค ๋ฉ”์†Œ๋“œ๋กœ ์ „๋‹ฌํ•ด์•ผํ•˜๋Š”์ง€ ์• ๋งค๋ชจํ˜ธํ•ด์ ธ์„œ ์˜ค๋ฅ˜ ๋ฐœ์ƒ

<Step.5> ์ถ”์ƒ ํด๋ž˜์Šค(Abstract Class)

  • ๊ธฐ๋Šฅ ๊ตฌํ˜„์ด ์—†์ด ํ˜ธ์ถœ๋ฐฉ๋ฒ•(์ด๋ฆ„)๋งŒ ํด๋ž˜์Šค์— ํ‘œ์‹œ๋œ ํด๋ž˜์Šค์ด๋‹ค.
    ใ„ด๋ฌด์กฐ๊ฑด ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•ด์„œ ์žฌ์ •์˜ํ•˜์—ฌ ์‚ฌ์šฉํ•ด์•ผ๋งŒ ํ•œ๋‹ค.
  • ์ถ”์ƒ ํด๋ž˜์Šค๋Š” ์–ด๋–ป๊ฒŒ ๋™์ž‘ํ•ด์•ผ ํ•˜๋Š”์ง€ ์•Œ ์ˆ˜ ์—†์œผ๋ฏ€๋กœ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์—†๋‹ค.
    ์ฆ‰, new๋ฅผ ์‚ฌ์šฉ ํ•  ์ˆ˜ ์—†๋‹ค.

<Step.6> ์ธํ„ฐํŽ˜์ด์Šค(Interface)

  • ์ƒ์† ๊ด€๊ณ„๊ฐ€ ์•„๋‹Œ ํด๋ž˜์Šค์— ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ๊ตฌ์กฐ์ด๋‹ค.
  • ์ธํ„ฐํŽ˜์ด์Šค์˜ ํŠน์ง•
  1. ์ธํ„ฐํŽ˜์ด์Šค๋ผ๋ฆฌ ์ƒ์†๋„ ๊ฐ€๋Šฅํ•˜๋‹ค
  2. ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ์ผ๋ฐ˜ ํด๋ž˜์Šค๋ฅผ ์ƒ์†ํ•  ์ˆ˜๋Š” ์—†๋‹ค.
  3. Java๋Š” ๋‹ค์ค‘์ƒ์†์ด ์—†๋‹ค. ์ธํ„ฐํŽ˜์ด์Šค๋Š” ๊ธฐ๋Šฅ๋งŒ ์žˆ์–ด ๋‹ค์ค‘์ƒ์†์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
  4. ์ธํ„ฐํŽ˜์ด์Šค๋กœ ์„ ์–ธํ•œ ๋ณ€์ˆ˜๋Š” public static final๋กœ ์„ ์–ธํ•œ๋‹ค.

<Step.7> ์ถ”์ƒ ํด๋ž˜์Šค์™€ ์ธํ„ฐํŽ˜์ด์Šค

  • ๊ทธ๋ ‡๋‹ค๋ฉด ์ธํ„ฐํŽ˜์ด์Šค์™€ ์ถ”์ƒ ํด๋ž˜์Šค์˜ ์ฐจ์ด๊ฐ€ ๋ฌด์—‡์ผ๊นŒ?
  1. ์ถ”์ƒํด๋ž˜์Šค๋Š” ์˜ค๋ฒ„๋ผ์ด๋”ฉ์„ ํ†ตํ•ด ์žฌ์ •์˜ํ•˜์—ฌ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋ฉฐ ์ƒ์†๊ณผ ๊ด€๋ จ์ด ์žˆ๋‹ค.
  2. ์ธํ„ฐํŽ˜์ด์Šค๋Š” ๋‹จ์ˆœํžˆ ๊ธฐ๋Šฅ๋งŒ์„ ์˜๋ฏธํ•œ๋‹ค.
  3. ์ถ”์ƒํด๋ž˜์Šค๋Š” ๋‹ค์ค‘์ƒ์†์ด ๋ถˆ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, ์ธํ„ฐํŽ˜์ด์Šค๋Š” ๋‹ค์ค‘ ์ƒ์†์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
  4. ์ถ”์ƒํด๋ž˜์Šค๋Š” ์ƒ์† ๊ด€๊ณ„๋ฅผ ์ญ‰ ํƒ€๊ณ  ์˜ฌ๋ผ๊ฐ”์„๋•Œ ๊ฐ™์€ ์กฐ์ƒํด๋ž˜์Šค๋ฅผ ์ƒ์†ํ•˜๋Š”๋ฐ
    ๊ธฐ๋Šฅ๊นŒ์ง€ ์™„๋ณ€ํžˆ ๋˜‘๊ฐ™์€ ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ฃผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค.
  5. ์ธํ„ฐํŽ˜์ด์Šค๋Š” ์ƒ์† ๊ด€๊ณ„๋ฅผ ์ญ‰ ํƒ€๊ณ  ์˜ฌ๋ผ๊ฐ”์„๋•Œ ๋‹ค๋ฅธ ์กฐ์ƒํด๋ž˜์Šค๋ฅผ ์ƒ์†ํ•˜๋Š”๋ฐ
    ๊ฐ™์€ ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•  ๊ฒฝ์šฐ ์ธํ„ฐํŽ˜์ด์Šค ์‚ฌ์šฉํ•œ๋‹ค.
  6. ์ถ”์ƒํด๋ž˜์Šค๋Š” IS - A "~์ด๋‹ค"์‹์œผ๋กœ ํ•ด์„๋œ๋‹ค.
  7. ์ธํ„ฐํŽ˜์ด์Šค๋Š” HAS - A "~์„ ํ•  ์ˆ˜ ์žˆ๋Š”"์‹์œผ๋กœ ํ•ด์„๋œ๋‹ค.
  • (์ถ”์ƒํด๋ž˜์Šค)๋Š” ํ•ด๋‹น ์ถ”์ƒํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›์•„์„œ ๊ธฐ๋Šฅ์„ ์ด์šฉํ•˜๊ณ  ํ™•์žฅ์‹œํ‚ค๋Š”๋ฐ ๋ชฉ์ 
  • (์ธํ„ฐํŽ˜์ด์Šค)๋Š” ํ•จ์ˆ˜์˜ ๊ป๋ฐ๊ธฐ๋งŒ ์žˆ๊ณ  ๊ทธ ํ•จ์ˆ˜์˜ ๊ตฌํ˜„์„ ๊ฐ•์ œํ•œ๋‹ค
  • ๊ทธ๋ ‡๋‹ค๋ฉด ์ธํ„ฐํŽ˜์ด์Šค์™€ ์ถ”์ƒ ํด๋ž˜์Šค์˜ ๊ณตํ†ต์ ์€ ๋ฌด์—‡์ผ๊นŒ?
  1. ์ถ”์ƒ ๋ฉ”์†Œ๋“œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์•ผ ํ•œ๋‹ค.
  2. ์ธ์Šคํ„ด์Šคํ™” ํ•  ์ˆ˜ ์—†๋‹ค (new ์ƒ์„ฑ์ž ์‚ฌ์šฉ X)
  3. ์ธํ„ฐํŽ˜์ด์Šค ํ˜น์€ ์ถ”์ƒ ํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›์•„ ๊ตฌํ˜„ํ•œ ๊ตฌํ˜„์ฒด์˜ ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.
  4. ์ธํ„ฐํŽ˜์ด์Šค์™€ ์ถ”์ƒํด๋ž˜์Šค๋ฅผ ๊ตฌํ˜„, ์ƒ์†ํ•œ ํด๋ž˜์Šค๋Š” ์ถ”์ƒ ๋ฉ”์†Œ๋“œ๋ฅผ ๋ฐ˜๋“œ์‹œ ๊ตฌํ˜„ํ•˜์—ฌ์•ผ ํ•œ๋‹ค.

<Step.8> ๋‹คํ˜•์„ฑ(polymorphism)

  • ํ•˜๋‚˜์˜ ๊ฐ์ฒด๊ฐ€ ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ํƒ€์ž…์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์„ ์˜๋ฏธ
  • ๋™์ผํ•œ ์กฐ์ž‘๋ฐฉ๋ฒ•์œผ๋กœ ๋™์ž‘์‹œํ‚ค์ง€๋งŒ ๋™์ž‘๋ฐฉ๋ฒ•์€ ๋‹ค๋ฅธ ๊ฒƒ.
    ใ„ดํ‚ค๋ณด๋“œ๋ฅผ ๋ˆ„๋ฅธ๋‹ค โ†’ ๊ฒฐ๊ณผ๋Š” ๋‹ค ๋‹ค๋ฅด๋‹ค๋Š” ๊ฒƒ๊ณผ ๊ฐ™์Œ.
  • ์ž๋ฐ”์—์„  ๋Œ€ํ‘œ์ ์œผ๋กœ ์˜ค๋ฒ„๋กœ๋”ฉ, ์˜ค๋ฒ„๋ผ์ด๋”ฉ, ์—…์บ์ŠคํŒ…, ๋‹ค์šด์บ์ŠคํŒ…,
    ์ธํ„ฐํŽ˜์ด์Šค, ์ถ”์ƒ๋ฉ”์†Œ๋“œ, ์ถ”์ƒํด๋ž˜์Šค๊ฐ€ ๋ชจ๋‘ ๋‹คํ˜•์„ฑ์— ํ•ด๋‹นํ•œ๋‹ค.
  • ๋‹คํ˜•์„ฑ์˜ ์žฅ์ 
  1. ์œ ์ง€๋ณด์ˆ˜ : ์—ฌ๋Ÿฌ ๊ฐ์ฒด๋ฅผ ํ•˜๋‚˜์˜ ํƒ€์ž…์œผ๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์šฉ์ดํ•˜๋‹ค.
  2. ์žฌ์‚ฌ์šฉ์„ฑ : ๊ฐ์ฒด์˜ ์žฌ์‚ฌ์šฉ์ด ์‰ฌ์›Œ ์žฌ์‚ฌ์šฉ์„ฑ์ด ๋†’์•„์ง„๋‹ค.
  3. ๋Š์Šจํ•œ ๊ฒฐํ•ฉ : ํด๋ž˜์Šค ๊ฐ„์˜ ์˜์กด์„ฑ์„ ์ค„์—ฌ ํ™•์žฅ์„ฑ์€ ๋†’์•„์ง€๊ณ  ๊ฒฐํ•ฉ๋„๋Š” ๋‚ฎ์•„์ง„๋‹ค.
  • ๋‹คํ˜•์„ฑ์˜ ํ™œ์šฉ
    ์นดํŽ˜์—์„œ ์ปคํ”ผ๋ฅผ ์ฃผ๋ฌธํ•˜๋Š” ๊ฒƒ์„ ์˜ˆ๋กœ Coffee ํด๋ž˜์Šค์—๋Š” ๊ฐ€๊ฒฉ ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ๋‹ค.
    Coffee ํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›๋Š” Amercano ํด๋ž˜์Šค์™€ CaffeLatte ํด๋ž˜์Šค๊ฐ€ ์กด์žฌํ•œ๋‹ค.
    ์†๋‹˜์€ 5๋งŒ ์›์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•œ๋‹ค.
class Coffee {
    int price;

    public Coffee(int price) {
        this.price = price;
    }
}

class Americano extends Coffee {
    public Americano() {
        super(4000); // ์ƒ์œ„ ๋ฉ”์„œ๋“œ ์ƒ์„ฑ์ž ํ˜ธ์ถœ
    }
    // Object ํด๋ž˜์Šค toString() ๋ฉ”์„œ๋“œ ์˜ค๋ฒ„๋ผ์ด๋”ฉ
    public String toString() { 
        return "์•„๋ฉ”๋ฆฌ์นด๋…ธ";
    }
}

class CaffeLatte extends Coffee {
    public CaffeLatte() {
        super(5000);
    }
    // Object ํด๋ž˜์Šค toString() ๋ฉ”์„œ๋“œ ์˜ค๋ฒ„๋ผ์ด๋”ฉ
    public String toString() {
        return "์นดํŽ˜๋ผ๋–ผ";
    }
}

class Customer {
    int money = 50000;

    // ์ปคํ”ผ ๊ตฌ๋งค ๋ฉ”์„œ๋“œ(๋‹คํ˜•์„ฑ ํ™œ์šฉ)
    void buyCoffee(Coffee coffee) {
        if (money < coffee.price) {
            System.out.println("์ž”์•ก์ด ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค.");
            return;
        }
        money -= coffee.price;
        System.out.println(coffee + "๋ฅผ ๊ตฌ๋งคํ•˜์˜€์Šต๋‹ˆ๋‹ค.");
    }

    /* ์•„๋ฉ”๋ฆฌ์นด๋…ธ, ์นดํŽ˜๋ผ๋–ผ ๊ตฌ๋งค ๋ฉ”์„œ๋“œ๋ฅผ ๋”ฐ๋กœ ๊ตฌํ˜„ํ•˜์ง€ ์•Š์•„๋„ ๋จ
    (์ƒ๋žต๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ ์ฃผ์„์ฒ˜๋ฆฌ)
    void buyCoffee(Americano americano) {
        money -= americano.price;
    }

    void buyCoffee(CaffeLatte caffeLatte) {
        money -= caffeLatte.price;
    } */
}
public class PolymorphismEx {
    public static void main(String[] args) {
        Customer me = new Customer();
        me.buyCoffee(new Americano());
        me.buyCoffee(new CaffeLatte());

        System.out.println("ํ˜„์žฌ ์ž”์•ก: " + me.money);
    }
}
  • ๋‹คํ˜•์„ฑ ์‚ฌ์šฉ์˜ ํšจ๊ณผ
  1. ๊ฐœ๋ณ„์ ์ธ ์ปคํ”ผ์˜ ๊ตฌ๋งค ๋ฉ”์„œ๋“œ๋ฅผ ๋”ฐ๋กœ ๊ตฌํ˜„ํ•˜์ง€ ์•Š๊ณ ,
    ์ƒ์œ„ ํด๋ž˜์Šค์ธ Coffee์˜ ์ž๋ฃŒํ˜•์„ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ๋ฐ›์œผ๋ฉด,
    ํ•˜์œ„ ํด๋ž˜์Šค ํƒ€์ž…์˜ ์ฐธ์กฐ ๋ณ€์ˆ˜๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ๋  ์ˆ˜ ์žˆ๋‹ค.
  2. ๋ฐ˜๋ณต์ ์ธ ์ฝ”๋“œ๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค.

<Step.9> Instanceof ์—ฐ์‚ฐ์ž

๊ฐ์ฒด๊ฐ€ ์–ด๋–ค ํด๋ž˜์Šค์ธ์ง€, ์–ด๋–ค ํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›์•˜๋Š”์ง€ ํ™•์ธํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•˜๋Š” ์—ฐ์‚ฐ์ž

class A { }
class B extends A { }   

public static void main(String[] args) {
  A mc1 = new A();
  B mc2 = new B();

  // mc1๋ณ€์ˆ˜๋Š” A ํด๋ž˜์Šค์—๊ฒŒ ์ƒ์†๋ฐ›์•˜๋‚˜์š”? true ์ถœ๋ ฅ
  System.out.println(mc1 instanceof A);   
  // mc2๋ณ€์ˆ˜๋Š” A ํด๋ž˜์Šค์—๊ฒŒ ์ƒ์†๋ฐ›์•˜๋‚˜์š”? A๋ฅผ ์ƒ์† ๋ฐ›์•˜๊ธฐ ๋•Œ๋ฌธ(true ์ถœ๋ ฅ)
  System.out.println(mc2 instanceof A); 
  // mc1๋ณ€์ˆ˜๋Š” B ํด๋ž˜์Šค์—๊ฒŒ ์ƒ์†๋ฐ›์•˜๋‚˜์š”? false ์ถœ๋ ฅ
  System.out.println(mc1 instanceof B);   
  // mc2๋ณ€์ˆ˜๋Š” B ํด๋ž˜์Šค์—๊ฒŒ ์ƒ์†๋ฐ›์•˜๋‚˜์š”? true ์ถœ๋ ฅ
  System.out.println(mc2 instanceof B);   
  • ๋ชจ๋“  ํด๋ž˜์Šค๋Š” Object๋ฅผ ์ƒ์†ํ•˜๊ธฐ ๋•Œ๋ฌธ์— Object Instanceof Object ๋Š”
    ใ„ดํ•ญ์ƒ true๋ผ๋Š” ๊ฐ’์ด ๋‚˜์˜จ๋‹ค.

<Step.10> ๋ฐœ์ „์„ ์œ„ํ•œ ๋ฌธ์ œํ’€์ด (kama_code ์ถœ์ œ)

  1. ์ƒ์†๊ด€๊ณ„์— ๋†“์—ฌ์žˆ๋Š” ํด๋ž˜์Šค์˜ ์ƒ์„ฑ์ž ์ •์˜ ๋ฐ ํ˜ธ์ถœ๋ฐฉ์‹์„ ๊ธฐ๋ณธ์œผ๋กœ
    ๋‚จ์€ ๊ณ ๊ธฐ๋Ÿ‰(๋ผ์ง€๊ณ ๊ธฐ 180g, ์†Œ๊ณ ๊ธฐ 600g, ์–‘๊ณ ๊ธฐ 540g)์„ ์ถœ๋ ฅํ•˜๋Š” ๋ฉ”์ธ ๋ฉ”์†Œ๋“œ๋ฅผ ์ •์˜ํ•˜์‹œ์˜ค.
  2. ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ์„ ๋ฐ›์•„ ์ƒ์†๊ด€๊ณ„์— ์žˆ๋Š” ๋‘ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด ์ ์ ˆํ•œ ์ƒ์„ฑ์ž์™€ ํ•จ๊ป˜
    ์ด๋ฆ„, ๋‚˜์ด, ์ฃผ์†Œ, ์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ์ธ์ž๋กœ ์ถœ๋ ฅ๋˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“œ์‹œ์˜ค.
  3. ๊ฐ€๋กœ์™€ ์„ธ๋กœ๋ฅผ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ์„ ๋ฐ›์•„์„œ
    ์ •์‚ฌ๊ฐํ˜•์„ ์˜๋ฏธํ•˜๋Š” Squareํด๋ž˜์Šค์™€ ์ง์‚ฌ๊ฐํ˜•์„ ์˜๋ฏธํ•˜๋Š” Rectangleํด๋ž˜์Šค๋ฅผ ์ •์˜ํ•˜๊ณ 
    ๋‘˜์˜ ๋ฉด์ ์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“œ์‹œ์˜ค.
  4. ๋ถˆ๊ณ ๊ธฐ๋ฒ„๊ฑฐ ๋‹จํ’ˆ 4500์›, ์‹์žฌ๋ฃŒ: ์‡ ๊ณ ๊ธฐํŒจํ‹ฐ, ์ผ€์ฐน, ํ”ผํด, ์„ธํŠธ๊ตฌ๋งค์‹œ
    ์ฝœ๋ผ 1000์›, ๊ฐ์žํŠ€๊น€ 1500์› ๊ณ ์ •์œผ๋กœ ์ถ”๊ฐ€
    ์น˜ํ‚จ๋ฒ„๊ฑฐ ๋‹จํ’ˆ 4200์›, ์‹์žฌ๋ฃŒ ๋‹ญ๊ณ ๊ธฐํŒจํ‹ฐ, ๋งˆ์š”๋„ค์ฆˆ, ์–‘์ƒ์ถ”,
    ์„ธํŠธ๊ตฌ๋งค์‹œ 500์› ํ• ์ธ์ด ๋˜๋Š”
    ํด๋ž˜์Šค์˜ ์ƒ์† ๊ด€๊ณ„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ถœ๋ ฅ๋˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“œ์‹œ์˜ค.
  5. ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ด๋ฆ„์„ ์ž…๋ ฅ๋ฐ›์•„ ์บ๋ฆญํ„ฐ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๋‹ค์–‘ํ•œ ๋ชฌ์Šคํ„ฐ์™€ ์ „ํˆฌ๋ฅผ ํŽผ์ณ
    ์•„์ดํ…œ์„ ๋–จ์–ด๋œจ๋ฆฌ๋Š” ๊ฐ„๋‹จํ•œ RPG ๊ฒŒ์ž„์„ ๋งŒ๋“œ์‹œ์˜ค.

โ˜… ์ •๋‹ต ๋ฐ ํ•ด์„ค โ˜†

  1. ๊ธฐ๋ณธ์ ์ธ ์ƒ์†์„ ์‚ฌ์šฉํ•œ ์ฝ”๋“œ์ด๋‹ค.
/*
์ƒ์†๊ด€๊ณ„์— ๋†“์—ฌ์žˆ๋Š” ํด๋ž˜์Šค์˜ ์ƒ์„ฑ์ž ์ •์˜ ๋ฐ ํ˜ธ์ถœ๋ฐฉ์‹์„ ๊ธฐ๋ณธ์œผ๋กœ 
๋‚จ์€ ๊ณ ๊ธฐ๋Ÿ‰(๋ผ์ง€๊ณ ๊ธฐ 180g, ์†Œ๊ณ ๊ธฐ 600g, ์–‘๊ณ ๊ธฐ 540g)์„ ์ถœ๋ ฅํ•˜๋Š” ๋ฉ”์ธ ๋ฉ”์†Œ๋“œ๋ฅผ ์ •์˜ํ•˜์‹œ์˜ค.
*/

class Meat // ๋ถ€๋ชจ ํด๋ž˜์Šค Meat
{		
	int pig; // intํ˜• pig ๋ณ€์ˆ˜
	public Meat(int pig) // ์ƒ์„ฑ์ž ์˜ค๋ฒ„๋ผ์ด๋”ฉ(๋งค๊ฐœ๋ณ€์ˆ˜ pig)
	{
		this.pig=pig; // ์ž์‹ ์˜ ๊ฐ์ฒด ์ ‘๊ทผ
	}	
}
class Cow extends Meat // Meat์— ์ƒ์†๋œ Cow ์ž์‹ ํด๋ž˜์Šค
{
	int cow; // intํ˜• cow ๋ณ€์ˆ˜
	public Cow(int pig, int cow)
	{
		super(pig); // ๋ถ€๋ชจ ํด๋ž˜์Šค๋กœ pig๋ฅผ ๋ณด๋ƒ„
		this.cow = cow; // ์ž์‹ ์˜ ๊ฐ์ฒด ์ ‘๊ทผ
	}
}

class Sheep extends Cow
{
	int sheep;
	public Sheep(int pig, int cow, int sheep)
	{
		super(pig, cow);
		this.sheep = sheep;
	}

	public void show()
	{
		System.out.println("๋‚จ์€ ๋ผ์ง€๊ณ ๊ธฐ: "+ pig + "g");
		System.out.println("๋‚จ์€ ์†Œ๊ณ ๊ธฐ: "+ cow + "g");
		System.out.println("๋‚จ์€ ์–‘๊ณ ๊ธฐ: "+ sheep + "g");
	}

}
public class Put01
{
	public static void main(String[] args)
	{
		Sheep first = new Sheep(180,600,540);
		first.show();
	}
}
  1. ์—ญ์‹œ 1๋ฒˆ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๊ธฐ๋ณธ์ ์ธ ์ƒ์†์„ ์‚ฌ์šฉํ•œ ์ฝ”๋“œ์ด๋‹ค.
/*
์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ์„ ๋ฐ›์•„ ์ƒ์†๊ด€๊ณ„์— ์žˆ๋Š” ๋‘ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด ์ ์ ˆํ•œ ์ƒ์„ฑ์ž์™€ ํ•จ๊ป˜
์ด๋ฆ„, ๋‚˜์ด, ์ฃผ์†Œ, ์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ์ธ์ž๋กœ ์ถœ๋ ฅ๋˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“œ์‹œ์˜ค.
*/

import java.util.Scanner;

class Person01
{
	public String name;
	int age;
	
	public Person01(String name,int age)
	{
		this.name = name;
		this.age = age;
	}
    
	public void PersonShow()
	{
		System.out.println("=====================");
		System.out.println("์ด๋ฆ„: "+name);
		System.out.println("๋‚˜์ด: "+age);
	}
}

class Person02 extends Person01
{
	private String address;
	private String number;
	
	public Person02(String name,int age,String address, String number)
	{
		super(name,age);
		this.address = address;
		this.number = number;
	}
	
	public void show()
	{
		PersonShow();
		System.out.println("์ฃผ์†Œ: "+address);
		System.out.println("์ „ํ™”๋ฒˆํ˜ธ: "+number);
		System.out.println("=====================");
	}
}

public class Put02
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		System.out.println("์ด๋ฆ„ ์ž…๋ ฅ: ");
		String name = scan.nextLine();
		System.out.println("์ฃผ์†Œ ์ž…๋ ฅ: ");
		String address = scan.nextLine();
		System.out.println("์ „ํ™”๋ฒˆํ˜ธ ์ž…๋ ฅ: ");
		String number = scan.nextLine();
		System.out.println("๋‚˜์ด ์ž…๋ ฅ: ");
		int age = scan.nextInt();
		Person02 info = new Person02(name, age, address, number);
		info.show();
	}
}
  1. ์—ญ์‹œ ๊ธฐ๋ณธ์ ์ธ ์ƒ์†์„ ์ด์šฉํ•œ ์ฝ”๋“œ์ด๋‹ค.
/*
๊ฐ€๋กœ์™€ ์„ธ๋กœ๋ฅผ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ์„ ๋ฐ›์•„์„œ 
์ •์‚ฌ๊ฐํ˜•์„ ์˜๋ฏธํ•˜๋Š” Squareํด๋ž˜์Šค์™€ ์ง์‚ฌ๊ฐํ˜•์„ ์˜๋ฏธํ•˜๋Š” Rectangleํด๋ž˜์Šค๋ฅผ ์ •์˜ํ•˜๊ณ 
๋‘˜์˜ ๋ฉด์ ์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“œ์‹œ์˜ค.
*/

class Square // ์ •์‚ฌ๊ฐํ˜• ๋ถ€๋ชจ ํด๋ž˜์Šค
{
	// ๋ฉค๋ฒ„ ๋ณ€์ˆ˜
	private int x; // ํ•œ๋ณ€ ์ •๋ณด ์€๋‹‰
	
	public Square(int x) // ์ƒ์„ฑ์ž
	{
		this.x=x;
	}	
	public void ShowSquare()
	{
		System.out.println("์ •์‚ฌ๊ฐํ˜•์˜ ๋ฉด์ : "+x*x);
	}
}

class Rectangle
{
	// ๋ฉค๋ฒ„ ๋ณ€์ˆ˜
	private int width; // ๊ฐ€๋กœ ์ •๋ณด ์€๋‹‰
	private int height; // ์„ธ๋กœ ์ •๋ณด ์€๋‹‰
	
	public Rectangle(int width, int height) // ์ƒ์„ฑ์ž
	{
		this.width = width;
		this.height = height;
	}
	
	public void ShowRectangle()
	{
		System.out.println("์ง์‚ฌ๊ฐํ˜•์˜ ๋ฉด์ : "+width*height);
	}
}

public class Put03
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		System.out.println("์ง์‚ฌ๊ฐํ˜•์˜ ๊ฐ€๋กœ: ");
		int w = scan.nextInt();
		System.out.println("์ง์‚ฌ๊ฐํ˜•์˜ ์„ธ๋กœ: ");
		int h = scan.nextInt();
		System.out.println("์ •์‚ฌ๊ฐํ˜•์˜ ํ•œ ๋ณ€: ");
		int j = scan.nextInt();
       	Rectangle rec = new Rectangle(w,h);
       	rec.ShowRectangle();

 		Square sqr = new Square(j);
       	sqr.ShowSquare();	
	}
}
  1. ์กฐ๊ธˆ ๋ณต์žกํ•ด์ง„ ํ”„๋กœ๊ทธ๋žจ์ด๋‹ค. ํ”„๋กœ๊ทธ๋žจ์€ ์ด๋ฒคํŠธ ๋˜๋Š” ์นœ์ ˆ์ด ๋“ค์–ด๊ฐ€๋ฉด
    ๋‚œ์ด๋„๊ฐ€ ์ƒ์Šนํ•œ๋‹ค.
    ์ค‘์š”ํ•œ ๊ฑด ๊ธฐ๋Šฅ์ด ์žˆ๋‹ค๋ฉด ๋†“์น˜์ง€ ๋ง๊ณ  ํ•˜๋‚˜ํ•˜๋‚˜ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.
    ์น˜ํ‚จ ๋ฒ„๊ฑฐ๋Š” ์„ธํŠธ๋ฅผ ์ฃผ๋ฌธ์‹œ 500์›์„ ํ• ์ธํ•˜๋Š”๋ฐ
    super.price()-500 => ๋ถ€๋ชจ ํด๋ž˜์Šค์˜ ๊ณ„์‚ฐ์‹์—์„œ 500์› ํ• ์ธํ•˜๋Š” ํฌ์ธํŠธ ์ค‘์š”ํ•˜๋‹ค.
    ๊ฒฐ๊ตญ ์ƒ์†์€ ์™”๋‹ค๊ฐ”๋‹ค ํ•˜๋ฉด์„œ ์žฌํ™œ์šฉ์„ ์ž˜ ์‚ฌ์šฉํ•˜๋Š”๋ฐ ์ค‘์š”์„ฑ์ด ์žˆ๋‹ค.
/*
๋ถˆ๊ณ ๊ธฐ๋ฒ„๊ฑฐ ๋‹จํ’ˆ 4500์›, ์‹์žฌ๋ฃŒ: ์‡ ๊ณ ๊ธฐํŒจํ‹ฐ, ์ผ€์ฐน, ํ”ผํด, ์„ธํŠธ๊ตฌ๋งค์‹œ 
์ฝœ๋ผ 1000์›, ๊ฐ์žํŠ€๊น€ 1500์› ๊ณ ์ •์œผ๋กœ ์ถ”๊ฐ€
์น˜ํ‚จ๋ฒ„๊ฑฐ ๋‹จํ’ˆ 4200์›, ์‹์žฌ๋ฃŒ ๋‹ญ๊ณ ๊ธฐํŒจํ‹ฐ, ๋งˆ์š”๋„ค์ฆˆ, ์–‘์ƒ์ถ”, 
์„ธํŠธ๊ตฌ๋งค์‹œ 500์› ํ• ์ธ์ด ๋˜๋Š”
ํด๋ž˜์Šค์˜ ์ƒ์† ๊ด€๊ณ„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ถœ๋ ฅ๋˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“œ์‹œ์˜ค.
*/

//ํ–„๋ฒ„๊ฑฐ๋ฅผ ์ถ”์ƒํ™”
class Burger
{
	/*
	 * ๋ฉค๋ฒ„๋ณ€์ˆ˜ : ๋ฒ„๊ฑฐ๋ช…, ๊ฐ€๊ฒฉ, ํŒจํ‹ฐ, ์†Œ์Šค, ์•ผ์ฑ„ ์ธ์ž์ƒ์„ฑ์ž ๋ฉค๋ฒ„๋ฉ”์†Œ๋“œ : 
	 * ๊ฐ€๊ฒฉ๋ฐ˜ํ™˜(getter), ํ–„๋ฒ„๊ฑฐ์ •๋ณด์ถœ๋ ฅ
	 */
	private String burgerName; //๋ฒ„๊ฑฐ๋ช… ์ •๋ณด ์€๋‹‰
	private int price; //๋ฒ„๊ฑฐ๋ช… ์ •๋ณด ์€๋‹‰
	private String patty; //ํŒจํ‹ฐ ์ •๋ณด ์€๋‹‰
	private String sauce; //์†Œ์Šค ์ •๋ณด ์€๋‹‰
	private String vegetable; //์•ผ์ฑ„ ์ •๋ณด ์€๋‹‰

	// ์ธ์ž์ƒ์„ฑ์ž
	public Burger(String burgerName, int price, String patty, String sauce, String vegetable)
	{
		super();
		this.burgerName = burgerName;
		this.price = price;
		this.patty = patty;
		this.sauce = sauce;
		this.vegetable = vegetable;
	}

	// getter/setter : private์œผ๋กœ ๊ฐ„์ ‘ ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด
	public String getBurgerName()
	{
		return burgerName;
	}

	public void setBurgerName(String burgerName)
	{
		this.burgerName = burgerName;
	}

	public int getPrice()
	{
		return price;
	}

	public void setPrice(int price)
	{
		this.price = price;
	}

	public String getPatty()
	{
		return patty;
	}

	public void setPatty(String patty)
	{
		this.patty = patty;
	}

	public String getSauce()
	{
		return sauce;
	}

	public void setSauce(String sauce)
	{
		this.sauce = sauce;
	}

	public String getVegetable()
	{
		return vegetable;
	}

	public void setVegetable(String vegetable)
	{
		this.vegetable = vegetable;
	}

	// ํ–„๋ฒ„๊ฑฐ ์ •๋ณด ์ถœ๋ ฅ
	public void showBurger()
	{
		System.out.println(burgerName);
		System.out.println("๊ฐ€๊ฒฉ:" + price);
		System.out.printf("์‹์žฌ๋ฃŒ:%s, %s, %s\n", patty, sauce, vegetable);
	}

}

// ํ–„๋ฒ„๊ฑฐ์˜ ๊ธฐ๋ณธ๊ฐ€๊ฒฉ ์ถ”์ƒํ™”
class HamburgerPrice
{
	// ๋ฉค๋ฒ„๋ณ€์ˆ˜
	Burger burger;// ๋””ํดํŠธ(default) ์ ‘๊ทผ์ง€์ •์ž๋กœ ์„ค์ •
	final int COKE = 1000; // ์ตœ์ข… ์ƒ์ˆ˜์ฒ˜๋ฆฌ 
	final int POTATO = 1500; // ์ตœ์ข… ์ƒ์ˆ˜์ฒ˜๋ฆฌ 

	// ์ธ์ž์ƒ์„ฑ์ž : ์ƒ์ˆ˜๋Š” ์ด๋ฏธ ์ดˆ๊ธฐํ™”๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ ํ–„๋ฒ„๊ฑฐ ๊ฐ์ฒด๋งŒ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค.
	public HamburgerPrice(Burger burger)
	{
		this.burger = burger;
	}

	// ๊ธฐ๋ณธ๊ฐ€๊ฒฉ๊ณ„์‚ฐ : ํ–„๋ฒ„๊ฑฐ + ์ฝœ๋ผ + ํ”„๋ Œ์น˜ํ”„๋ผ์ด ๊ฐ€๊ฒฉ์˜ ํ•ฉ
	public int price()
	{
		// ํ–„๋ฒ„๊ฑฐ์˜ price๋Š” private ์ด๋ฏ€๋กœ getter๋ฅผ ํ†ตํ•ด ๊ฐ€์ ธ์™€์•ผ ํ•จ.
		int total = burger.getPrice() + COKE + POTATO;
		return total;
	}

	// ํ–„๋ฒ„๊ฑฐ์™€ ๊ฒฐ์ œ๊ธˆ์•ก ์ถœ๋ ฅ
	public void showPrice()
	{
		burger.showBurger();// ํ–„๋ฒ„๊ฑฐ์˜ ์ •๋ณด ์ถœ๋ ฅ
		System.out.println("์„ธํŠธ๊ฒฐ์ œ๊ธˆ์•ก:" + price());
		System.out.println("==========================");
	}
}

// ํ–„๋ฒ„๊ฑฐ์˜ ์„ธํŠธ๊ฐ€๊ฒฉ (๊ธฐ๋ณธ๊ฐ€๊ฒฉ์„ ์ƒ์†)
class SetPrice extends HamburgerPrice
{

	// ์ธ์ž์ƒ์„ฑ์ž
	public SetPrice(Burger burger)
	{
		// ๋ถ€๋ชจํด๋ž˜์Šค์— ์ •์˜๋œ ์ธ์ž์ƒ์„ฑ์ž ํ˜ธ์ถœ
		super(burger);
	}

	// ์„ธํŠธ๊ฐ€๊ฒฉ๊ณ„์‚ฐ(์˜ค๋ฒ„๋ผ์ด๋”ฉ) : 500์› ํ• ์ธ๋œ ๊ฐ€๊ฒฉ์œผ๋กœ ๊ณ„์‚ฐํ•จ.
	@Override
	public int price()
	{
		// ๋ถ€๋ชจ์˜ ๊ธฐ๋ณธ๊ฐ€๊ฒฉ ๊ณ„์‚ฐ์‹์—์„œ 500์› ์ฐจ๊ฐ
		return super.price() - 500;
	}

	// ํ–„๋ฒ„๊ฑฐ์™€ ์„ธํŠธ๊ฐ€๊ฒฉ์„ ์ถœ๋ ฅ(์˜ค๋ฒ„๋ผ์ด๋”ฉ)
	@Override
	public void showPrice()
	{
		// ๋””ํดํŠธ ์ ‘๊ทผ์ง€์ •์ž๋Š” ๋™์ผ ํŒจํ‚ค์ง€์—์„œ๋Š” ์ ‘๊ทผ์„ ํ—ˆ์šฉํ•จ.
		burger.showBurger();
		System.out.println("์„ธํŠธํ• ์ธ๊ธˆ์•ก:" + price());
		System.out.println("============================");
	}
}

public class Put04
{
	public static void main(String[] args)
	{

		// ์น˜์ฆˆ๋ฒ„๊ฑฐ ๊ฐ์ฒด ์ƒ์„ฑ
		Burger burger1 = new Burger("๋ถˆ๊ณ ๊ธฐ๋ฒ„๊ฑฐ", 4500, "์‡ ๊ณ ๊ธฐํŒจํ‹ฐ", "์ผ€์ฑฑ", "ํ”ผํด");
		// ์น˜ํ‚จ๋ฒ„๊ฑฐ ๊ฐ์ฒด ์ƒ์„ฑ
		Burger burger2 = new Burger("์น˜ํ‚จ๋ฒ„๊ฑฐ", 4200, "๋‹ญ๊ณ ๊ธฐํŒจํ‹ฐ", "๋งˆ์š”๋„ค์ฆˆ", "์–‘์ƒ์ถ”");

		// ์น˜์ฆˆ๋ฒ„๊ฑฐ๋ฅผ ๊ธฐ๋ณธ๊ฐ€๊ฒฉ์œผ๋กœ ๊ตฌ๋งค
		HamburgerPrice price1 = new HamburgerPrice(burger1);
		price1.showPrice(); // 4500์›

		// ์น˜ํ‚จ๋ฒ„๊ฑฐ๋ฅผ ์„ธํŠธ๊ฐ€๊ฒฉ์œผ๋กœ ๊ตฌ๋งค
		HamburgerPrice price2 = new SetPrice(burger2);
		price2.showPrice(); // 4200์›
	}
}
  1. ์ฝ”๋“œ์™€ ํด๋ž˜์Šค๊ฐ€ ๊ต‰์žฅํžˆ ๋งŽ๊ณ  ๊ธธ๋‹ค.
    ๊ฒŒ์ž„์„ ๋งŒ๋“œ๋Š”๋ฐ๋Š” ์›๋ž˜ ์–ด๋งˆ์–ด๋งˆํ•œ ์ฝ”๋“œ๊ฐ€ ํ•„์š”ํ•˜๋‹ค.
    ์ž๋ฐ”์—์„œ ํ•ต์‹ฌ์€ ํด๋ž˜์Šค๋ฅผ ํ•œ ํŒŒ์ผ์•ˆ์— ๋ชจ๋‘ ๋ชฐ์•„๋„ฃ์„ ์ˆ˜ ์žˆ์ง€๋งŒ
    ํด๋ž˜์Šค๋Š” ๋ฐ˜๋“œ์‹œ ๋‹ค๋ฅธ ํŒŒ์ผ์— ๋‚˜๋ˆ„์–ด์„œ ํ•˜๋‚˜์”ฉ ๋‹ด๋Š” ๊ฒƒ์ด ๊ฐœ๋ฐœ์— ํ—ค๊น”๋ฆฌ์ง€๋„ ์•Š์„๋ฟ๋”๋Ÿฌ
    ์žฅ์ ์ด ๋งŽ๋‹ค.

ํ•ต์‹ฌ์€ ์ƒ์†! ํฐ ๊ทธ๋ฃน์ด ๋ฌด์—‡์ด๋ฉฐ, ๊ทธ ์•ˆ์— ์–ด๋– ํ•œ ์ƒ์† ๊ด€๊ณ„์— ์žˆ๋Š” ํด๋ž˜์Šค๋“ค์ด ์žˆ๋Š”์ง€๋ฅผ
์งœ์•ผํ•œ๋‹ค. ๊ทธ ๋‹ค์Œ ๊ทธ ๊ทธ๋ฃน ํด๋ž˜์Šค๋งˆ๋‹ค ์ž‘์€ ๋””ํ…Œ์ผํ•œ ๊ธฐ๋Šฅ๋“ค์„ ๋งŒ๋“ค์–ด์ฃผ๋ฉด ๋œ๋‹ค.

  • ๊ฒŒ์ž„์˜ ๋ฉ”์ธ ์ฝ”๋“œ์ด๋‹ค. ํŒจํ‚ค์ง€๋ช… Main ์•ˆ์— ๋งŒ๋“ค์–ด์ค€๋‹ค.
package Main;

import java.util.Scanner;

import Character.*;

import Map.*;

public class GameMain {

	public static void main(String[] args) {
		// ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ์„ ๋ฐ›๋Š”๋‹ค.
		Scanner sc = new Scanner(System.in);
		// hero ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑ
		Hero hero = new Hero();
		// ๋ฉ”๋‰ด
		System.out.println("*******RPG GAME*******");
		System.out.println("1. ์ „์‚ฌ");
		System.out.println("2. ๋งˆ๋ฒ•์‚ฌ");
		System.out.println("3. ๊ถ์‚ฌ");
		System.out.printf("์ง์—…์˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”. : ");
		int num = sc.nextInt();
		
		// 1๋ฒˆ, ์ „์‚ฌ๋ฅผ ์„ ํƒ์‹œ ์ดˆ๊ธฐํ™” ์…‹ํŒ…
		if(num == 1) {
			
			System.out.println("์ „์‚ฌ๊ฐ€ ์„ ํƒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
			hero = new Warrior(); // ์บ๋ฆญํ„ฐ๋Š” ์ „์‚ฌ
			hero.defense = 25; // ๋ฐฉ์–ด๋ ฅ
			hero.power = 15; // ๊ณต๊ฒฉ๋ ฅ
			hero.level = 1; // ๋ ˆ๋ฒจ
			hero.hp = 80; // ์ฒด๋ ฅ
			hero.mp = 0; // ๋งˆ๋ ฅ
			
		}
		// 2๋ฒˆ, ๋งˆ๋ฒ•์‚ฌ๋ฅผ ์„ ํƒ์‹œ ์ดˆ๊ธฐํ™” ์…‹ํŒ…
		else if(num == 2) {
			
			System.out.println("๋งˆ๋ฒ•์‚ฌ๊ฐ€ ์„ ํƒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
			hero = new Magician();// ์บ๋ฆญํ„ฐ๋Š” ๋งˆ๋ฒ•์‚ฌ
			hero.defense = 10; // ๋ฐฉ์–ด๋ ฅ
			hero.power = 18; // ๊ณต๊ฒฉ๋ ฅ
			hero.level = 1; // ๋ ˆ๋ฒจ
			hero.hp = 60; // ์ฒด๋ ฅ
			hero.mp = 60; // ๋งˆ๋ ฅ
		
		}
		// 3๋ฒˆ, ๊ถ์‚ฌ๋ฅผ ์„ ํƒ์‹œ ์ดˆ๊ธฐํ™” ์…‹ํŒ…
		else if(num == 3) {
			
			System.out.println("๊ถ์‚ฌ๊ฐ€ ์„ ํƒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
			hero = new Archer();// ์บ๋ฆญํ„ฐ๋Š” ๊ถ์‚ฌ
			hero.defense = 5; // ๋ฐฉ์–ด๋ ฅ
			hero.power = 20; // ๊ณต๊ฒฉ๋ ฅ
			hero.level = 1; // ๋ ˆ๋ฒจ
			hero.hp = 50; // ์ฒด๋ ฅ
			hero.mp = 0; //๋งˆ๋ ฅ
		
		}
		
		// ์ด๋ฆ„์„ ์„ ํƒํ•  ๊ฐ’์„ ๋ฐ›๋Š”๋‹ค.
		System.out.printf("์˜์›…์˜ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”. : ");
		hero.name = sc.next();
		System.out.println("์ด๋ฆ„์ด ์ •์ƒ์ ์œผ๋กœ ์ž…๋ ฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
		System.out.println("๊ฒŒ์ž„์— ์ž…์žฅํ•˜์˜€์Šต๋‹ˆ๋‹ค.");
		
		// ๊ฒŒ์ž„ ํ‹€์—์„œ ๋‚˜๊ฐ€์ง€ ๋ชปํ•˜๋„๋ก ๋ฌดํ•œ๋ฃจํ”„
		while(true) {
			
			System.out.println("*********************");
			System.out.println("ํ˜„์žฌ "+ hero.name + "์˜ ์ด๋ฆ„ : " + hero.name);
			System.out.println("ํ˜„์žฌ "+ hero.name + "์˜ ๋ ˆ๋ฒจ : " + hero.level);
			System.out.println("ํ˜„์žฌ "+ hero.name + "์˜ ํž˜ : " + hero.power);
			System.out.println("ํ˜„์žฌ "+ hero.name + "์˜ ๋ฐฉ์–ด๋ ฅ : " + hero.defense);
			System.out.println("ํ˜„์žฌ "+ hero.name + "์˜ HP : " + hero.hp);
			System.out.println("ํ˜„์žฌ "+ hero.name + "์˜ MP : "  + hero.mp);
			System.out.println("ํ˜„์žฌ "+ hero.name + "์˜ ๊ฒฝํ—˜์น˜ : "  + hero.experience);
			System.out.println("ํ˜„์žฌ "+ hero.name + "์˜ ๋ˆ : "  + hero.money + "์›");
			System.out.println("*********************");
			
			System.out.println("1. ์‚ฌ๋ƒฅํ„ฐ");
			System.out.println("2. ๋ฌด๊ธฐ ์ƒ์ ");
			System.out.println("3. ํฌ์…˜ ์ƒ์ ");
			System.out.printf("์ž…์žฅํ•  ์žฅ์†Œ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”. : ");
			num = sc.nextInt();
			
			// ์‚ฌ๋ƒฅํ„ฐ ์ž…์žฅ
			if(num == 1) {
				// ๋ชฌ์Šคํ„ฐ ๊ฐ์ฒด ์ƒ์„ฑ
				Monster monster = new Monster();
				System.out.println("์‚ฌ๋ƒฅํ„ฐ์— ์ž…์žฅํ•˜์˜€์Šต๋‹ˆ๋‹ค.");
				System.out.println("1. ๋„ˆ๊ตฌ๋ฆฌ");
				System.out.println("2. ์‚ด์พก์ด");
				System.out.println("3. ๋“ค๊ฐœ");
				System.out.println("4. ๋ฉง๋ผ์ง€");
				System.out.printf("์‚ฌ๋ƒฅํ•œ ๋ชฌ์Šคํ„ฐ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”. : ");
				num = sc.nextInt();
				
				// ๋„ˆ๊ตฌ๋ฆฌ ๋ชฌ์Šคํ„ฐ ์ดˆ๊ธฐํ™”
				if(num == 1) {
					
					monster = new Racoon();
					monster.name = "๋„ˆ๊ตฌ๋ฆฌ";
					monster.hp = 100;
					monster.mp = 0;
					monster.level = 1;
					monster.power = 20;
					monster.defense = 5;
					monster.money = 10;
					monster.experience = 10;
					System.out.println(monster.name + "๊ณผ ์ „ํˆฌ๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.");
				}
				
				// ์‚ด์พก์ด ๋ชฌ์Šคํ„ฐ ์ดˆ๊ธฐํ™”
				if(num == 2) {
					
					monster = new WildCat();
					monster.name = "์‚ด์พก์ด";
					monster.hp = 2000;
					monster.mp = 0;
					monster.level = 5;
					monster.power = 100;
					monster.defense = 20;
					monster.money = 30;
					monster.experience = 50;
					System.out.println(monster.name + "๊ณผ ์ „ํˆฌ๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.");
				}
				
				// ๋“ค๊ฐœ ๋ชฌ์Šคํ„ฐ ์ดˆ๊ธฐํ™”
				if(num == 3) {
					
					monster = new WildDog();
					monster.name = "๋“ค๊ฐœ";
					monster.hp = 3000;
					monster.mp = 0;
					monster.level = 15;
					monster.power = 300;
					monster.defense = 30;
					monster.money = 50;
					monster.experience = 100;
					System.out.println(monster.name + "๊ณผ ์ „ํˆฌ๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.");
				}
				
				// ๋ฉง๋ผ์ง€ ๋ชฌ์Šคํ„ฐ ์ดˆ๊ธฐํ™”
				if(num == 4) {
					
					monster = new WildPig();
					monster.name = "๋ฉง๋ผ์ง€";
					monster.hp = 10000;
					monster.mp = 0;
					monster.level = 30;
					monster.power = 1000;
					monster.defense = 80;
					monster.money = 200;
					monster.experience = 300;
					System.out.println(monster.name + "๊ณผ ์ „ํˆฌ๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.");
				}
				// ๊ณต๊ฒฉ์˜ ํ‹€์„ ๋ฒ—์–ด๋‚˜์ง€ ๋ชปํ•˜๋„๋ก ๋ฌดํ•œ๋ฃจํ”„
				while(true) {
					
					System.out.println(hero.name + "์˜ ๊ณต๊ฒฉ์ž…๋‹ˆ๋‹ค.");
					// ์—ฌ๊ธฐ์„œ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด์„œ ํ˜ธ์ถœํ•œ๋‹ค.
					monster.attacked(hero.attack()); 
					
					// ๋ชฌ์Šคํ„ฐ์˜ ์ฒด๋ ฅ์ด 0์ด๋ฉด
					if(monster.hp <= 0) {
						
						System.out.println(monster.name + "๊ฐ€ ์ฃฝ์—ˆ์Šต๋‹ˆ๋‹ค.");
						// ๊ฒฝํ—˜์น˜์™€ ๋ˆ์ด ์ฆ๊ฐ€
						hero.experience += monster.experience;
						hero.money += monster.money;
						break;
					}
					
					System.out.println(monster.name + "์˜ ๊ณต๊ฒฉ์ž…๋‹ˆ๋‹ค.");
					// ์—ฌ๊ธฐ์„œ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด์„œ ํ˜ธ์ถœํ•œ๋‹ค.
					hero.attacked(monster.attack());
					
					// ์ฃฝ์œผ๋ฉด ๊ฒŒ์ž„์„ ์ด์–ด๋‚˜๊ฐ€๊ธฐ ์œ„ํ•ด ์ฒด๋ ฅ 1๋กœ ๋ถ€ํ™œํ•œ๋‹ค
					if(hero.hp <= 0) {
						
						System.out.println(hero.name + "์ด ์ฃฝ์—ˆ์Šต๋‹ˆ๋‹ค.");
						hero.hp = 1;
						System.out.println(hero.name + "์ด ์ฒด๋ ฅ" + hero.hp + "์œผ๋กœ ๋ถ€ํ™œํ–ˆ์Šต๋‹ˆ๋‹ค.");
						break;
					}
				}
				// ๋ฌด๊ธฐ ์ƒ์ 
			}else if(num == 2) {
				// ๋ฌด๊ธฐ์ƒ์  ๊ฐ์ฒด ์ƒ์„ฑ
				WeaponStore weaponstore = new WeaponStore();
				System.out.println("๋ฌด๊ธฐ ์ƒ์ ์— ์ž…์žฅํ•˜์˜€์Šต๋‹ˆ๋‹ค.");
				System.out.println("1. ๊ณต๋™ ๋ฌด๊ธฐ (50์›)");
				System.out.println("2. ๊ณต๋™ ๋ฐฉํŒจ (50์›)");
				System.out.println("ํ˜„์žฌ ๋ˆ์ด " + hero.money  + "์žˆ์Šต๋‹ˆ๋‹ค.");
				System.out.printf("์›ํ•˜์‹œ๋Š” ๋ฌผ๊ฑด์„ ์ž…๋ ฅํ•˜์„ธ์š”. : ");
				
				num = sc.nextInt();
				// ์ƒ์  ๊ฑฐ๋ž˜๋ฅผ ์œ„ํ•ด ํ”Œ๋ ˆ์ด์–ด์˜ ๋ˆ์„ temp ๋ณ€์ˆ˜์— ๋„ฃ๋Š”๋‹ค.
				int temp = hero.money;
				
				// ํ”Œ๋ ˆ์ด์–ด์˜ ๋ˆ์ด ์Œ์ˆ˜๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ๊ตฌ๋งค๊ฐ€ ๊ฐ€๋Šฅ
				if((hero.money = weaponstore.show(hero.money,num)) != -1) 
				{
					
					System.out.println("๊ตฌ์ž…์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
					// ๋ฌด๊ธฐ๋ฅผ ๊ตฌ๋งคํ•  ๊ฒฝ์šฐ
					if(num == 1) {
						// ๊ณต๊ฒฉ๋ ฅ 5๊ฐ€ ์ฆ๊ฐ€
						hero.power += 5;
					}
					// ๋ฐฉํŒจ๋ฅผ ๊ตฌ๋งคํ•  ๊ฒฝ์šฐ
					if(num == 2) {
						// ๋ฐฉ์–ด๋ ฅ 5๊ฐ€ ์ฆ๊ฐ€
						hero.defense += 5;
						
					}
					
					System.out.println(temp + "์› ๋‚จ์•˜์Šต๋‹ˆ๋‹ค.");
					
				}else {
					System.out.println("๋ˆ์ด ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค.");
					System.out.println(temp + "์› ๋‚จ์•˜์Šต๋‹ˆ๋‹ค.");
				}
				// ํฌ์…˜ ์ƒ์  ์ž…์žฅ
			}else if(num == 3) {
				
				// ํฌ์…˜ ์ƒ์  ๊ฐ์ฒด ์ƒ์„ฑ
				PotionStore potionstore = new PotionStore();
				System.out.println("ํฌ์…˜ ์ƒ์ ์— ์ž…์žฅํ•˜์˜€์Šต๋‹ˆ๋‹ค.");
				System.out.println("1. ๊ณต๊ฒฉ๋ ฅ ์ฆ๊ฐ€ ํฌ์…˜ (30์›)");
				System.out.println("2. ๋ฐฉ์–ด๋ ฅ ์ฆ๊ฐ€ ํฌ์…˜ (30์›)");
				System.out.println("3. ๊ฒฝํ—˜์น˜ ์ฆ๊ฐ€ ํฌ์…˜ (100์›)");
				System.out.println("4. HP ์ฆ๊ฐ€ ํฌ์…˜ (10์›)");
				System.out.println("5. MP ์ฆ๊ฐ€ ํฌ์…˜ (10์›)");
				System.out.printf("์›ํ•˜์‹œ๋Š” ๋ฌผ๊ฑด์„ ์ž…๋ ฅํ•˜์„ธ์š”. : ");
				
				// ์ž…๋ ฅ๊ฐ’์„ int ์ •์ˆ˜ num ๋ณ€์ˆ˜์— ์ €์žฅํ•œ๋‹ค.
				num = sc.nextInt();
				// ๋ˆ์„ temp ์— ์—ญ์‹œ ๋„ฃ๋Š”๋‹ค.
				int temp = hero.money;
				// ํ”Œ๋ ˆ์ด์–ด์˜ ๋ˆ์ด ์Œ์ˆ˜๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ๊ตฌ๋งค๊ฐ€ ๊ฐ€๋Šฅ
				if((hero.money = potionstore.show(hero.money,num)) != -1) {
					
					System.out.println("๊ตฌ์ž…์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
					
					
					if(num == 1) {
						// ๊ณต๊ฒฉ๋ ฅ ์ฆ๊ฐ€ +3 
						hero.power += 3;
					}
					
					if(num == 2) {
						// ๋ฐฉ์–ด๋ ฅ ์ฆ๊ฐ€ +3 
						hero.defense += 3;	
					}
					if(num == 3) {
						// ๊ฒฝํ—˜์น˜ ์ฆ๊ฐ€ +50 
						hero.experience += 50;	
					}
					if(num == 4) {
						// ์ฒด๋ ฅ ์ฆ๊ฐ€ +50 
						hero.hp += 50;
					}
					if(num == 5) {
						// ๋งˆ๋ ฅ ์ฆ๊ฐ€ +50 
						hero.mp += 50;
					}
					
					System.out.println(temp + "์› ๋‚จ์•˜์Šต๋‹ˆ๋‹ค.");
					
				}else {
					System.out.println("๋ˆ์ด ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค.");
					System.out.println(temp + "์› ๋‚จ์•˜์Šต๋‹ˆ๋‹ค.");
				}
			}
			// ๋ ˆ๋ฒจ์— x80ํ•œ๋งŒํผ ๊ฒฝํ—˜์น˜๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์„ ๊ฒฝ์šฐ๋ฅผ ๋ ˆ๋ฒจ์—… ๊ธฐ์ค€
			if(hero.experience  >= hero.level * 80) 
			{
				// ๋ ˆ๋ฒจ์ด 1 ์˜ค๋ฅธ๋‹ค.
				hero.level += 1;
				System.out.println(hero.name + "์˜ ๋ ˆ๋ฒจ์ด" + hero.level + "์ด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
				// ๋ˆ์€ ๋ ˆ๋ฒจ์˜ x50ํ•œ ๋งŒํผ ์ค€๋‹ค
				hero.money += hero.level * 50;
				System.out.println("๋ ˆ๋ฐธ์—… ๊ธฐ๋…์œผ๋กœ ๋ˆ์ด " + hero.level * 50 + "์› ์ฆ๊ฐ€ํ•˜์—ฌ ");
				System.out.println(hero.money + "์›์ด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
				hero.experience = 0; // ๊ฒฝํ—˜์น˜ ์ดˆ๊ธฐํ™”
			}
			
		}
	}
}		
  • Map ํด๋ž˜์Šค์ด๋‹ค. ํŒจํ‚ค์ง€๋ช… Map์„ ๋จผ์ € ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ฃผ์˜!
package Map;
// ์ง€๋„ ํด๋ž˜์Šค๋Š” ์ด๋ฆ„์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค
public class Map {
	String  name;
}
  • PotionStore ํด๋ž˜์Šค์ด๋‹ค. ํŒจํ‚ค์ง€๋ช… Map์„ ๋จผ์ € ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ฃผ์˜!
package Map;
//Map ๋ถ€๋ชจ ํด๋ž˜์Šค์— ์ƒ์†๋œ PotionStore
public class PotionStore extends Map
{
	// ๋ฉค๋ฒ„ ๋ณ€์ˆ˜์™€ ์ดˆ๊ธฐํ™”๋ฅผ ์ง์ ‘ํ•œ๋‹ค
	int powerPotion = 30;
	int defensePotion = 30;
	int experiencePotion = 100;
	int hpPotion = 10;
	int mpPotion = 10;
	
	// ๋ฉค๋ฒ„ ๋ฉ”์†Œ๋“œ
	public int show(int money, int num) 
	{
		
		name = "ํฌ์…˜ ์ƒ์ ";
		System.out.println(name + "์—์„œ ๋ฌผ๊ฑด์„ ๊ตฌ๋งค ์‹œ๋„ํ•˜๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.");
		// ํž˜ํฌ์…˜์„ ์ƒ€์„๋•Œ
		if(num == 1) 
		{
			// ๋ˆ์ด ์žˆ์–ด์•ผ ํ•˜๋ฉฐ
			if(powerPotion <= money) 
			{
				// ๊ฐ€์ง„ ๋ˆ์—์„œ ๊ฐ’์„ ๋บ€๋‹ค
				return money - powerPotion;
			}
		}
		
		if(num == 2) {
			if(defensePotion <= money) {
				return money - defensePotion;
			}
		}
		
		if(num == 3) 
		{
			if(experiencePotion <= money) 
			{
				return money - experiencePotion;
			}
		}
		
		if(num == 4) 
		{
			if(hpPotion <= money) 
			{
				return money - hpPotion;
			}
		}
		
		if(num == 5) 
		{
			if(mpPotion <= money) 
			{
				return money - mpPotion;
			}
		}
		return money;
	}
}
  • WeaponStore ํด๋ž˜์Šค์ด๋‹ค. ํŒจํ‚ค์ง€๋ช… Map์„ ๋จผ์ € ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ฃผ์˜!
package Map;
//Map ๋ถ€๋ชจ ํด๋ž˜์Šค์— ์ƒ์†๋œ WeaponStore
public class WeaponStore extends Map 
{
	// ์ง์ ‘ ์ดˆ๊ธฐํ™”ํ•œ ๋ฉค๋ฒ„๋ณ€์ˆ˜
	int commonWeapon = 50;
	int commonShield = 50;
	
	// ๋ฉค๋ฒ„ ๋ฉ”์†Œ๋“œ
	public int show(int money, int num) {
		
		name = "๋ฌด๊ธฐ ์ƒ์ ";
		System.out.println(name + "์—์„œ ๋ฌผ๊ฑด์„ ๊ตฌ๋งค ์‹œ๋„ํ•˜๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.");
		// ๊ณตํ†ต ๋ฌด๊ธฐ๋ฅผ ์‚ด ๊ฒฝ์šฐ
		if(num == 1) {
			// ๋ˆ์ด ์žˆ์„ ๊ฒฝ์šฐ -> ๊ฐ€๊ฒฉ์„ ๋บ€ ๊ฐ’์„ ๋ฐ˜ํ™˜
			if(commonWeapon <= money) {
				return money - commonWeapon;
			}
		}
		
		if(num == 2) {
			if(commonShield <= money) {
				return money - commonShield;
			}
		}
		
		return money;
	}
}
  • ํŒจํ‚ค์ง€๋ช… Character์„ ๋จผ์ € ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ฃผ์˜!
package Character;

import java.util.Scanner;

// hero ๋ถ€๋ชจ ํด๋ž˜์Šค์— ์ƒ์†๋œ Archer
public class Archer extends Hero {
	// ๋ฉค๋ฒ„ ๋ฉ”์†Œ๋“œ
	public int attack() {
		
		Scanner sc = new Scanner(System.in);
		System.out.println("1. ํ™”์‚ด ๊ณต๊ฒฉ");
		System.out.println("2. ์—ฐ์† ํ™”์‚ด ๊ณต๊ฒฉ");
		System.out.printf("๊ณต๊ฒฉ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : ");
		int num = sc.nextInt();
		// ๋Šฅ๋ ฅ์น˜๋ฅผ 0์œผ๋กœ ์ดˆ๊ธฐํ™” ํ•ด ๋†“๋Š”๋‹ค.
		int sum = 0;
		// ํ™”์‚ด๊ณต๊ฒฉ
		if(num == 1) {
			// ๋ ˆ๋ฒจ์˜ 15๋ฐฐ+๊ณต๊ฒฉ๋ ฅ 15๋ฐฐ+๋ฐฉ์–ด๋ ฅ 15๋ฐฐ์˜ ๋ฐ๋ฏธ์ง€๋กœ ๋“ค์–ด๊ฐ„๋‹ค.
			sum += level * 15;
			sum += power * 15;
			sum += defense * 15;
			System.out.println("๋ฐ๋ฏธ์ง€๋Š” " + sum + " ์ž…๋‹ˆ๋‹ค.");
			return sum;
			// ์—ฐ์† ํ™”์‚ด ๊ณต๊ฒฉ
		}else if(num == 2) {
			// ๋ ˆ๋ฒจ์˜ 10๋ฐฐ+๊ณต๊ฒฉ๋ ฅ 20๋ฐฐ+๋ฐฉ์–ด๋ ฅ 10๋ฐฐ์˜ ๋ฐ๋ฏธ์ง€๋กœ ๋“ค์–ด๊ฐ„๋‹ค.
			sum += level * 10;
			sum += power * 20;
			sum += defense * 10;
			System.out.println("๋ฐ๋ฏธ์ง€๋Š” " + sum + " ์ž…๋‹ˆ๋‹ค.");
			return sum;
			
		}
		System.out.println("๋ฐ๋ฏธ์ง€๋Š” " + sum + " ์ž…๋‹ˆ๋‹ค.");
		return sum;
	}
	
	//Archer.attacked์„ ๋ถˆ๋ €์„ ๊ฒฝ์šฐ
	public void attacked(int sum) {
		// ๋ฐฉ์–ด๋ ฅ์ด ๋” ํฌ๋ฉด ํ”ผํ•ด๋ฅผ ์ž…์ง€ ์•Š๋Š”๋‹ค.
		if(defense >= sum) {
			hp = hp - 0;
		}else 
		{
			//์ฒด๋ ฅ+๋ฐฉ์–ด๋ ฅ์—์„œ ๋ฐ๋ฏธ์ง€๋ฅผ ๋บ€ ๊ฐ’์ด ์ฒด๋ ฅ์œผ๋กœ ๋‚จ๋Š”๋‹ค.
			hp = hp + defense - sum;
		}
	}
}
  • ํŒจํ‚ค์ง€๋ช… Character์„ ๋จผ์ € ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ฃผ์˜!
package Character;
// ์บ๋ฆญํ„ฐ ํด๋ž˜์Šค
public class Character {
// ์ด๋ฆ„๊ณผ hp mp ๋ ˆ๋ฒจ์ด ๋ฉค๋ฒ„๋ณ€์ˆ˜๋กœ ์€๋‹‰ํ™”
	public String name;
	public int hp;
	public int mp;
	public int level;
}
  • ํŒจํ‚ค์ง€๋ช… Character์„ ๋จผ์ € ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ฃผ์˜!
package Character;
//Character ๋ถ€๋ชจ ํด๋ž˜์Šค์— ์ƒ์†๋œ Hero
public class Hero extends Character {
	// ์ง์ ‘์ ์œผ๋กœ ๋ฉค๋ฒ„๋ณ€์ˆ˜ ์„ ์–ธ๊ณผ ์ดˆ๊ธฐํ™”
	public int power;
	public int defense;
	public int money = 0;
	public int experience = 0;
	// ๋ฉค๋ฒ„ ๋ฉ”์†Œ๋“œ๋ฅผ ๋ถˆ๋ €์„๋•Œ ๊ณต๊ฒฉ๋ ฅ์„ ๋ฐ˜ํ™˜
	public int attack() {
		return power;
	}
	//Hero.attacked์„ ๋ถˆ๋ €์„ ๊ฒฝ์šฐ
	public void attacked(int sum) {
		// ๊ฐ’๋ณด๋‹ค ๋ฐฉ์–ด๋ ฅ์ด ๋” ํฌ๋ฉด
		if(defense >= sum) {
			// ํ”ผํ•ด๋ฅผ ์ž…์ง€ ์•Š๋Š”๋‹ค
			hp = hp - 0;
		}else 
		{
			// ๊ทธ ์™ธ๋Š” ์ฒด๋ ฅ๊ณผ ๋ฐฉ์–ด๋ ฅ์„ ๋”ํ•œ ๊ฐ’์—์„œ ๋ฐ๋ฏธ์ง€๋งŒํผ ๋นผ์„œ ์ฒด๋ ฅ์œผ๋กœ ๋‚จ์Œ
			hp = hp + defense - sum;
		}
	}
}
  • ํŒจํ‚ค์ง€๋ช… Magician์„ ๋จผ์ € ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ฃผ์˜!
package Character;

import java.util.Scanner;
//hero ๋ถ€๋ชจ ํด๋ž˜์Šค์— ์ƒ์†๋œ Magician
public class Magician extends Hero {
	// ๋ฉค๋ฒ„ ๋ฉ”์†Œ๋“œ
	public int attack() {
		// ๋Šฅ๋ ฅ์น˜๋ฅผ ์ดˆ๊ธฐํ™”
		int sum = 0;
		
		// ๋งˆ๋ ฅ์ด 10๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์„๋•Œ๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
		if(mp >= 10) {
			
			Scanner sc = new Scanner(System.in);
			System.out.println("1. ํŒŒ์ด์–ด๋ณผ");
			System.out.println("2. ์›Œํ„ฐ๋ณผ");
			System.out.printf("๊ณต๊ฒฉ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : ");
			int num = sc.nextInt();
		
		// ํŒŒ์ด์–ด๋ณผ : ๋ ˆ๋ฒจ์˜ 10๋ฐฐ+๊ณต๊ฒฉ๋ ฅ์˜ 15๋ฐฐ+๋ฐฉ์–ด๋ ฅ์˜ 5๋ฐฐ๊ฐ€ ๋ฐ๋ฏธ์ง€๋กœ
		if(num == 1) {
			
			sum += level * 10;
			sum += power * 15;
			sum += defense * 5;
			System.out.println("๋ฐ๋ฏธ์ง€๋Š” " + sum + " ์ž…๋‹ˆ๋‹ค.");
			//๋งˆ๋ ฅ์ด 5 ๊นŽ์ธ๋‹ค
			mp = mp - 5;
			return sum;
			
		// ์›Œํ„ฐ๋ณผ : ๋ ˆ๋ฒจ์˜ 8๋ฐฐ+๊ณต๊ฒฉ๋ ฅ์˜ 13๋ฐฐ+๋ฐฉ์–ด๋ ฅ์˜ 10๋ฐฐ๊ฐ€ ๋ฐ๋ฏธ์ง€๋กœ	
		}else if(num == 2) {
			
			sum += level * 8;
			sum += power * 13;
			sum += defense * 10;
			System.out.println("๋ฐ๋ฏธ์ง€๋Š” " + sum + " ์ž…๋‹ˆ๋‹ค.");
			//๋งˆ๋ ฅ์ด 5 ๊นŽ์ธ๋‹ค
			mp = mp - 5;
			return sum;
		}
		
		System.out.println("๋ฐ๋ฏธ์ง€๋Š” " + sum + " ์ž…๋‹ˆ๋‹ค.");
		return sum;
		
		// ๋งˆ๋ ฅ์ด 10๋ณด๋‹ค ์ž‘์„ ๊ฒฝ์šฐ
		}else 
		{
			System.out.println("MP๊ฐ€ ๋‚จ์•„์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.");
			return sum;
		}
	}
	//Magician.attacked์„ ๋ถˆ๋ €์„ ๊ฒฝ์šฐ
	public void attacked(int sum) {
		// ๋ฐฉ์–ด๋ ฅ์ด ๋ฐ๋ฏธ์ง€๋ณด๋‹ค ํฌ๋ฉด ๋ฐ๋ฏธ์ง€ ์—†์Œ
		if(defense >= sum) {
			hp = hp - 0;
		}else 
		{
			// ๊ทธ ์™ธ๋Š” ์ฒด๋ ฅ๊ณผ ๋ฐฉ์–ด๋ ฅ์„ ๋”ํ•œ ๊ฐ’์— ๋ฐ๋ฏธ์ง€๋ฅผ ๋บ€ ๊ฐ’์ด ์ฒด๋ ฅ์œผ๋กœ ๋‚จ์•„ ๋ฐ˜ํ™˜
			hp = hp + defense - sum;
		}
	}
}
  • ํŒจํ‚ค์ง€๋ช… Monster์„ ๋จผ์ € ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ฃผ์˜!
package Character;

//Character ๋ถ€๋ชจ ํด๋ž˜์Šค์— ์ƒ์†๋œ Monster
public class Monster extends Character{
	// ๋ฉค๋ฒ„๋ณ€์ˆ˜ ์€๋‹‰ํ™”
	public int power;
	public int defense;
	public int money;
	public int experience;
	
	// ์–ดํƒ ๋ฉค๋ฒ„ ๋ฉ”์†Œ๋“œ๋ฅผ ๋ถˆ๋ €์„๋•Œ ๊ณต๊ฒฉ๋ ฅ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค
	public int attack() {
		return power;
	}
	
	public void attacked(int sum) {
		
		if(defense >= sum) 
		{
			hp = hp - 0;
		}
		else {
			hp = hp + defense - sum;
		}
	}
}
  • ํŒจํ‚ค์ง€๋ช… Racoon์„ ๋จผ์ € ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ฃผ์˜!
package Character;

public class Racoon extends Monster {
	
	public int attack() {
		
		System.out.println("๋ฐ๋ฏธ์ง€๋Š” " + power + " ์ž…๋‹ˆ๋‹ค.");
		return power;
		
	}
	
	public void attacked(int sum) {
		
		if(defense >= sum) {
			hp = hp - 0;
		}else {
			hp = hp + defense - sum;
		}
	}
}
  • ํŒจํ‚ค์ง€๋ช… Warrior์„ ๋จผ์ € ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ฃผ์˜!
package Character;

import java.util.Scanner;
//Hero ๋ถ€๋ชจ ํด๋ž˜์Šค์— ์ƒ์†๋œ Warrior
public class Warrior extends Hero {
		
	public int attack() {
		
		Scanner sc = new Scanner(System.in);
		System.out.println("1. ์“ฐ๋Ÿฌ์ŠคํŠธ");
		System.out.println("2. ์‚ผ๋‹จ ๋ฒ ๊ธฐ");
		System.out.printf("๊ณต๊ฒฉ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : ");
		int num = sc.nextInt();
		
		int sum = 0;
		
		if(num == 1) {
			
			sum += level * 10;
			sum += power * 30;
			System.out.println("๋ฐ๋ฏธ์ง€๋Š” " + sum + " ์ž…๋‹ˆ๋‹ค.");
			return sum;
		}else if(num == 2) {
			
			sum += level * 20;
			sum += power * 15;
			sum += defense * 15;
			System.out.println("๋ฐ๋ฏธ์ง€๋Š” " + sum + " ์ž…๋‹ˆ๋‹ค.");
			return sum;
		}
		System.out.println("๋ฐ๋ฏธ์ง€๋Š” " + sum + " ์ž…๋‹ˆ๋‹ค.");
		return sum;
	}
	
	public void attacked(int sum) {
		
		if(defense >= sum) {
			hp = hp - 0;
		}else {
			hp = hp + defense - sum;
		}
	}
}
  • ํŒจํ‚ค์ง€๋ช… WildCat์„ ๋จผ์ € ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ฃผ์˜!
package Character;
//WildCat ํด๋ž˜์Šค๋Š” Monster๊ฐ€ ๋ถ€๋ชจ ํด๋ž˜์Šค ์ƒ์†
public class WildCat extends Monster {
	// ๋ฉค๋ฒ„ ๋ฉ”์†Œ๋“œ
	public int attack() {
		
		System.out.println("๋ฐ๋ฏธ์ง€๋Š” " + power + " ์ž…๋‹ˆ๋‹ค.");
		return power;
		
	}
	//WildCat.attacked์„ ๋ถˆ๋ €์„ ๊ฒฝ์šฐ
	public void attacked(int sum) {
		// ๋ฐ๋ฏธ์ง€๊ฐ€ ๋ฐฉ์–ด๋ ฅ๋ณด๋‹ค ์ž‘์œผ๋ฉด ํ”ผํ•ด ์—†์Œ
		if(defense >= sum) {
			hp = hp - 0;
		}else {
			// ๊ทธ ์ด์™ธ๋Š” ์ฒด๋ ฅ+๋ฐฉ์–ด๋ ฅ-๋ฐ๋ฏธ์ง€ = ์ฒด๋ ฅ์œผ๋กœ ๋‚จ๋Š”๋‹ค.
			hp = hp + defense - sum;
		}
	}
}
  • ํŒจํ‚ค์ง€๋ช… WildDog์„ ๋จผ์ € ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ฃผ์˜!
package Character;
//WildDog ํด๋ž˜์Šค๋Š” Monster๊ฐ€ ๋ถ€๋ชจ ํด๋ž˜์Šค ์ƒ์†
public class WildDog extends Monster {
	// ๋ฉค๋ฒ„ ๋ฉ”์†Œ๋“œ
	public int attack() {
		
		System.out.println("๋ฐ๋ฏธ์ง€๋Š” " + power + " ์ž…๋‹ˆ๋‹ค.");
		return power;
		
	}
	//WildDog.attacked์„ ๋ถˆ๋ €์„ ๊ฒฝ์šฐ
	public void attacked(int sum) {
		// ๋ฐ๋ฏธ์ง€๊ฐ€ ๋ฐฉ์–ด๋ ฅ๋ณด๋‹ค ์ž‘์œผ๋ฉด ํ”ผํ•ด ์—†์Œ
		if(defense >= sum) {
			hp = hp - 0;
		}else {
			// ๊ทธ ์ด์™ธ๋Š” ์ฒด๋ ฅ+๋ฐฉ์–ด๋ ฅ-๋ฐ๋ฏธ์ง€ = ์ฒด๋ ฅ์œผ๋กœ ๋‚จ๋Š”๋‹ค.
			hp = hp + defense - sum;
		}
	}
}
  • ํŒจํ‚ค์ง€๋ช… WildPig์„ ๋จผ์ € ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ทธ ์•ˆ์— ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ฃผ์˜!
package Character;
// WildPig ํด๋ž˜์Šค๋Š” Monster๊ฐ€ ๋ถ€๋ชจ ํด๋ž˜์Šค ์ƒ์†
public class WildPig extends Monster {
	// ๋ฉค๋ฒ„ ๋ฉ”์†Œ๋“œ
	public int attack() {
		
		System.out.println("๋ฐ๋ฏธ์ง€๋Š” " + power + " ์ž…๋‹ˆ๋‹ค.");
		return power;
		
	}
	//WildPig.attacked์„ ๋ถˆ๋ €์„ ๊ฒฝ์šฐ
	public void attacked(int sum) {
		// ๋ฐ๋ฏธ์ง€๊ฐ€ ๋ฐฉ์–ด๋ ฅ๋ณด๋‹ค ์ž‘์œผ๋ฉด ํ”ผํ•ด ์—†์Œ
		if(defense >= sum) {
			hp = hp - 0;
		}else {
			// ๊ทธ ์ด์™ธ๋Š” ์ฒด๋ ฅ+๋ฐฉ์–ด๋ ฅ-๋ฐ๋ฏธ์ง€ = ์ฒด๋ ฅ์œผ๋กœ ๋‚จ๋Š”๋‹ค.
			hp = hp + defense - sum;
		}
	}
}
  • ์ด๋ ‡๊ฒŒ ์ƒ์†๊นŒ์ง€ ๋์ด ๋‚ฌ๋‹ค. ์ƒ์†์€ ํšจ์œจ์„ ๊ทน๋Œ€ํ™”ํ•˜๊ณ  ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์งœ๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์—
    ์ง€๋Šฅ๊ณผ ๋…ผ๋ฆฌ ์‚ฌ๊ณ ๊ฐ€ ํ•„์š”ํ•œ ํŒŒํŠธ์ด๋‹ค.
    ๋‹ค์Œ ํฌ์ŠคํŒ…์—๋„ ์—ญ์‹œ ๊ฟ€ ๋–จ์–ด์ง€๋Š” ํฌ์ŠคํŒ…์€ ๊ณ„์†๋œ๋‹น!
profile
[Java SQL HTML CSS JS Studying] ๋ฐœ์ „์„ ๊ฟˆ๊พธ๋ฉฐ ์ด์ƒ์„ ์‹คํ˜„ํ•ฉ๋‹ˆ๋‹ค
post-custom-banner

2๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 7์›” 17์ผ

์ €๋„ ๊ฐœ๋ฐœ์ž์ธ๋ฐ ๊ฐ™์ด ๊ต๋ฅ˜ ๋งŽ์ด ํ•ด๋ด์š” ใ…Žใ…Ž! ์„œ๋กœ ํ™”์ดํŒ…ํ•ฉ์‹œ๋‹ค!

1๊ฐœ์˜ ๋‹ต๊ธ€