Skip to content

Commit

Permalink
move package
Browse files Browse the repository at this point in the history
  • Loading branch information
haero77 committed Jan 26, 2024
1 parent 169d86d commit 7b8b13d
Show file tree
Hide file tree
Showing 20 changed files with 668 additions and 0 deletions.
11 changes: 11 additions & 0 deletions OOP/projects/OBJECTS/OBJECTS.iml
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>
8 changes: 8 additions & 0 deletions OOP/projects/OBJECTS/ch01/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 01 티켓 판매 애플리케이션 구현하기

## 요구사항

- 관람객 맞이하기
- 이벤트에 당첨된 관람객과 그렇지 않은 관람객을 다르게 입장시켜야한다.
- 당첨된 관람객은 초대장을 티켓으로 교환한 후에 입장 가능하다.
- 당첨되지 않은 관람객은 티켓을 구매한 다음에 입장 가능하다.
18 changes: 18 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_01/Audience.java
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;
}

}
45 changes: 45 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_01/Bag.java
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;
}

}
9 changes: 9 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_01/Invitation.java
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;

}
26 changes: 26 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_01/Theater.java
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);
}
}

}
11 changes: 11 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_01/Ticket.java
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;
}

}
32 changes: 32 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_01/TicketOffice.java
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;
}

}
19 changes: 19 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_01/TicketSeller.java
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;
}

}
29 changes: 29 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_03/Audience.java
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();
}
}

}
43 changes: 43 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_03/Bag.java
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;
}

}
9 changes: 9 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_03/Invitation.java
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;

}
18 changes: 18 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_03/Theater.java
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);
}

}
11 changes: 11 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_03/Ticket.java
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;
}

}
32 changes: 32 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_03/TicketOffice.java
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;
}

}
19 changes: 19 additions & 0 deletions OOP/projects/OBJECTS/ch01/ch01_03/TicketSeller.java
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()));
}

}
Loading

0 comments on commit 7b8b13d

Please sign in to comment.