-
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.
Browse files
Browse the repository at this point in the history
[WIP] 온라인 영화 예매 시스템 코드 구현하기
- Loading branch information
Showing
11 changed files
with
146 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,4 @@ | ||
package study.book.object.movie; | ||
|
||
public class Customer { | ||
} |
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,47 @@ | ||
package study.book.object.movie; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import java.math.BigDecimal; | ||
|
||
@Getter @Setter | ||
@ToString | ||
public class Money { | ||
public static final Money ZERO = Money.wons(0); | ||
|
||
private final BigDecimal amount; | ||
|
||
public static Money wons(long amount) { | ||
return new Money(BigDecimal.valueOf(amount)); | ||
} | ||
|
||
public static Money wons(double amount) { | ||
return new Money(BigDecimal.valueOf(amount)); | ||
} | ||
|
||
Money(BigDecimal amount) { | ||
this.amount = amount; | ||
} | ||
|
||
public Money plus(Money amount) { | ||
return new Money(this.amount.subtract(amount.amount)); | ||
} | ||
|
||
public Money times(double percent) { | ||
return new Money(this.amount.multiply(BigDecimal.valueOf(percent))); | ||
} | ||
|
||
public Money minus(Money amount) { | ||
return new Money(this.amount.add(amount.amount)); | ||
} | ||
|
||
public boolean isLessThan(Money other) { | ||
return amount.compareTo(other.amount) < 0; | ||
} | ||
|
||
public boolean isGreaterThanOrEqual(Money other) { | ||
return amount.compareTo(other.amount) >= 0; | ||
} | ||
} |
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,17 @@ | ||
package study.book.object.movie; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import java.math.BigDecimal; | ||
|
||
@Getter @Setter | ||
@ToString | ||
public class Movie { | ||
private Money fee; | ||
|
||
public Money calculateMovieFee(Screening screening) { | ||
return fee.minus(new Money(BigDecimal.ZERO)); | ||
} | ||
} |
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 study.book.object.movie; | ||
|
||
import lombok.ToString; | ||
|
||
@ToString | ||
public class Reservation { | ||
private Customer customer; | ||
private Screening screening; | ||
private Money fee; | ||
private int audienceCount; | ||
|
||
public Reservation(Customer customer, Screening screening, Money fee, int audienceCount) { | ||
this.customer = customer; | ||
this.screening = screening; | ||
this.fee = fee; | ||
this.audienceCount = audienceCount; | ||
} | ||
|
||
} |
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,35 @@ | ||
package study.book.object.movie; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class Screening { | ||
private Movie movie; | ||
private int sequece; | ||
private LocalDateTime whenScreened; | ||
|
||
public Screening(Movie movie, int sequence, LocalDateTime whenScreened) { | ||
this.movie = movie; | ||
this.sequece = sequence; | ||
this.whenScreened = whenScreened; | ||
} | ||
|
||
public Reservation reserve(Customer customer, int audienceCount) { | ||
return new Reservation(customer, this, calculateFee(audienceCount), audienceCount); | ||
} | ||
|
||
public LocalDateTime getStartTime() { | ||
return whenScreened; | ||
} | ||
|
||
public boolean isSequence(int sequence) { | ||
return this.sequece == sequece; | ||
} | ||
|
||
public Money getMovieFee() { | ||
return movie.getFee(); | ||
} | ||
|
||
private Money calculateFee(int audienceCount) { | ||
return movie.calculateMovieFee(this); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/study/book/object/movie/condition/DiscountCondition.java
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,4 @@ | ||
package study.book.object.movie.condition; | ||
|
||
public class DiscountCondition { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/study/book/object/movie/condition/PeriodCondition.java
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,4 @@ | ||
package study.book.object.movie.condition; | ||
|
||
public class PeriodCondition { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/study/book/object/movie/condition/SequenceCondition.java
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,4 @@ | ||
package study.book.object.movie.condition; | ||
|
||
public class SequenceCondition { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/study/book/object/movie/policy/AmountDiscountPolicy.java
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,4 @@ | ||
package study.book.object.movie.policy; | ||
|
||
public class AmountDiscountPolicy { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/study/book/object/movie/policy/DiscountPolicy.java
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,4 @@ | ||
package study.book.object.movie.policy; | ||
|
||
public class DiscountPolicy { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/study/book/object/movie/policy/PercentDiscountPolicy.java
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,4 @@ | ||
package study.book.object.movie.policy; | ||
|
||
public class PercentDiscountPolicy { | ||
} |