-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
668 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# 01 티켓 판매 애플리케이션 구현하기 | ||
|
||
## 요구사항 | ||
|
||
- 관람객 맞이하기 | ||
- 이벤트에 당첨된 관람객과 그렇지 않은 관람객을 다르게 입장시켜야한다. | ||
- 당첨된 관람객은 초대장을 티켓으로 교환한 후에 입장 가능하다. | ||
- 당첨되지 않은 관람객은 티켓을 구매한 다음에 입장 가능하다. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ch01.ch01_01; | ||
|
||
/** | ||
* 관람객 | ||
*/ | ||
public class Audience { | ||
|
||
private Bag bag; | ||
|
||
public Audience(Bag bag) { | ||
this.bag = bag; | ||
} | ||
|
||
public Bag getBag() { | ||
return bag; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ch01.ch01_01; | ||
|
||
import ch01.ch01_01.Ticket; | ||
|
||
/** | ||
* 관람객이 소지품을 보관할 용도로 들고오는 가방 | ||
*/ | ||
public class Bag { | ||
|
||
private Long amount; | ||
private Invitation invitation; | ||
private Ticket ticket; | ||
|
||
// 이벤트 당첨되지 않은 관람객은 초대장이 없다. | ||
public Bag(long amount) { // Long이 아닌 long 을 사용함으로써 인스턴스 생성 시점에 amount가 null인 것을 방지 | ||
this(null, amount); | ||
} | ||
|
||
// 이벤트 당첨된 관람객 | ||
public Bag(Invitation invitation, long amount) { | ||
this.amount = amount; | ||
this.invitation = invitation; | ||
} | ||
|
||
public boolean hasInvitation() { | ||
return invitation != null; | ||
} | ||
|
||
public boolean hasTicket() { | ||
return ticket != null; | ||
} | ||
|
||
public void setTicket(Ticket ticket) { | ||
this.ticket = ticket; | ||
} | ||
|
||
public void minusAmount(Long amount) { | ||
this.amount -= amount; | ||
} | ||
|
||
public void plusAmount(Long amount) { | ||
this.amount += amount; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ch01.ch01_01; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class Invitation { | ||
|
||
private LocalDateTime when; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ch01.ch01_01; | ||
|
||
/** | ||
* 소극장 | ||
*/ | ||
public class Theater { | ||
|
||
private TicketSeller ticketSeller; | ||
|
||
public Theater(TicketSeller ticketSeller) { | ||
this.ticketSeller = ticketSeller; | ||
} | ||
|
||
public void enter(Audience audience) { | ||
if (audience.getBag().hasInvitation()) { | ||
Ticket ticket = ticketSeller.getTicketOffice().getTicket(); | ||
audience.getBag().setTicket(ticket); | ||
} else { | ||
Ticket ticket = ticketSeller.getTicketOffice().getTicket(); | ||
audience.getBag().minusAmount(ticket.getFee()); | ||
ticketSeller.getTicketOffice().plusAmount(ticket.getFee()); | ||
audience.getBag().setTicket(ticket); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ch01.ch01_01; | ||
|
||
public class Ticket { | ||
|
||
private Long fee; | ||
|
||
public Long getFee() { | ||
return fee; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ch01.ch01_01; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* 매표소. | ||
* 관람객이 소극장 입장할 때 매표소에서 초대장을 티켓으로 교환하거나 구매. | ||
*/ | ||
public class TicketOffice { | ||
|
||
private Long amount; | ||
private List<Ticket> tickets = new ArrayList<>(); | ||
|
||
public TicketOffice(Long amount, List<Ticket> tickets) { | ||
this.amount = amount; | ||
this.tickets = tickets; | ||
} | ||
|
||
public Ticket getTicket() { | ||
return tickets.remove(0); | ||
} | ||
|
||
public void minusAmount(Long amount) { | ||
this.amount -= amount; | ||
} | ||
|
||
public void plusAmount(Long amount) { | ||
this.amount += amount; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ch01.ch01_01; | ||
|
||
/** | ||
* 판매원. | ||
* 매표소에서 초대장을 티켓으로 교환해 주거나 티켓을 판매하는 역할 수행. | ||
*/ | ||
public class TicketSeller { | ||
|
||
private TicketOffice ticketOffice; | ||
|
||
public TicketSeller(TicketOffice ticketOffice) { | ||
this.ticketOffice = ticketOffice; | ||
} | ||
|
||
public TicketOffice getTicketOffice() { | ||
return ticketOffice; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package ch01.ch01_03; | ||
|
||
/** | ||
* 관람객 | ||
*/ | ||
public class Audience { | ||
|
||
private Bag bag; | ||
|
||
public Audience(Bag bag) { | ||
this.bag = bag; | ||
} | ||
|
||
public Bag getBag() { | ||
return bag; | ||
} | ||
|
||
public long buy(Ticket ticket) { | ||
if (this.bag.hasInvitation()) { | ||
this.bag.setTicket(ticket); | ||
return 0L; | ||
} else { | ||
this.bag.setTicket(ticket); | ||
this.bag.minusAmount(ticket.getFee()); | ||
return ticket.getFee(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ch01.ch01_03; | ||
|
||
/** | ||
* 관람객이 소지품을 보관할 용도로 들고오는 가방 | ||
*/ | ||
public class Bag { | ||
|
||
private Long amount; | ||
private Invitation invitation; | ||
private Ticket ticket; | ||
|
||
// 이벤트 당첨되지 않은 관람객은 초대장이 없다. | ||
public Bag(long amount) { // Long이 아닌 long 을 사용함으로써 인스턴스 생성 시점에 amount가 null인 것을 방지 | ||
this(null, amount); | ||
} | ||
|
||
// 이벤트 당첨된 관람객 | ||
public Bag(Invitation invitation, long amount) { | ||
this.amount = amount; | ||
this.invitation = invitation; | ||
} | ||
|
||
public boolean hasInvitation() { | ||
return invitation != null; | ||
} | ||
|
||
public boolean hasTicket() { | ||
return ticket != null; | ||
} | ||
|
||
public void setTicket(Ticket ticket) { | ||
this.ticket = ticket; | ||
} | ||
|
||
public void minusAmount(Long amount) { | ||
this.amount -= amount; | ||
} | ||
|
||
public void plusAmount(Long amount) { | ||
this.amount += amount; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ch01.ch01_03; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class Invitation { | ||
|
||
private LocalDateTime when; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ch01.ch01_03; | ||
|
||
/** | ||
* 소극장 | ||
*/ | ||
public class Theater { | ||
|
||
private TicketSeller ticketSeller; | ||
|
||
public Theater(TicketSeller ticketSeller) { | ||
this.ticketSeller = ticketSeller; | ||
} | ||
|
||
public void enter(Audience audience) { | ||
ticketSeller.sellTo(audience); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ch01.ch01_03; | ||
|
||
public class Ticket { | ||
|
||
private Long fee; | ||
|
||
public Long getFee() { | ||
return fee; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ch01.ch01_03; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* 매표소. | ||
* 관람객이 소극장 입장할 때 매표소에서 초대장을 티켓으로 교환하거나 구매. | ||
*/ | ||
public class TicketOffice { | ||
|
||
private Long amount; | ||
private List<Ticket> tickets = new ArrayList<>(); | ||
|
||
public TicketOffice(Long amount, List<Ticket> tickets) { | ||
this.amount = amount; | ||
this.tickets = tickets; | ||
} | ||
|
||
public Ticket getTicket() { | ||
return tickets.remove(0); | ||
} | ||
|
||
public void minusAmount(Long amount) { | ||
this.amount -= amount; | ||
} | ||
|
||
public void plusAmount(Long amount) { | ||
this.amount += amount; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ch01.ch01_03; | ||
|
||
/** | ||
* 판매원. | ||
* 매표소에서 초대장을 티켓으로 교환해 주거나 티켓을 판매하는 역할 수행. | ||
*/ | ||
public class TicketSeller { | ||
|
||
private TicketOffice ticketOffice; | ||
|
||
public TicketSeller(TicketOffice ticketOffice) { | ||
this.ticketOffice = ticketOffice; | ||
} | ||
|
||
public void sellTo(Audience audience) { | ||
this.ticketOffice.plusAmount(audience.buy(ticketOffice.getTicket())); | ||
} | ||
|
||
} |
Oops, something went wrong.