Skip to content

[1장_김명석] Pull Request #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/legacy/kms/chapter01/Audience.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package legacy.kms.chapter01;

public class Audience {
class Audience {

private final Bag bag;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/legacy/kms/chapter01/Bag.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package legacy.kms.chapter01;

public class Bag {
class Bag {

private Long amount;
private Invitation invitation;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/legacy/kms/chapter01/Invitation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.time.LocalDateTime;

public class Invitation {
class Invitation {

private LocalDateTime when;
}
2 changes: 1 addition & 1 deletion src/main/java/legacy/kms/chapter01/Theater.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package legacy.kms.chapter01;

public class Theater {
class Theater {

private final TicketSeller ticketSeller;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/legacy/kms/chapter01/Ticket.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package legacy.kms.chapter01;

public class Ticket {
class Ticket {

private Long fee;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/legacy/kms/chapter01/TicketOffice.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Arrays;
import java.util.List;

public class TicketOffice {
class TicketOffice {

private Long amount;
private final List<Ticket> tickets = new ArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/legacy/kms/chapter01/TicketSeller.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package legacy.kms.chapter01;

public class TicketSeller {
class TicketSeller {

private final TicketOffice ticketOffice;

Expand Down
4 changes: 0 additions & 4 deletions src/main/kotlin/kms/InitClass.kt

This file was deleted.

14 changes: 14 additions & 0 deletions src/main/kotlin/kms/chapter01/Audience.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package kms.chapter01

internal class Audience(private val bag: Bag) {

fun buy(ticket: Ticket): Long {
return if (bag.hasInvitation()) {
bag.setTicket(ticket)
0L
} else {
bag.minusAmount(ticket.fee)
ticket.fee
}
}
}
27 changes: 27 additions & 0 deletions src/main/kotlin/kms/chapter01/Bag.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package kms.chapter01

internal class Bag(
private var amount: Long = 0,
private val invitation: Invitation? = null,
private var ticket: Ticket? = null,
) {
fun hasInvitation(): Boolean {
return invitation != null
}

fun hasTicket(): Boolean {
return ticket != null
}

fun setTicket(ticket: Ticket?) {
this.ticket = ticket
}

fun minusAmount(amount: Long) {
this.amount = this.amount - amount
}

fun plusAmount(amount: Long) {
this.amount = this.amount + amount
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/kms/chapter01/Invitation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kms.chapter01

import java.time.LocalDateTime

internal class Invitation(
private val whenDateTime: LocalDateTime,
)
9 changes: 9 additions & 0 deletions src/main/kotlin/kms/chapter01/Theater.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package kms.chapter01

internal class Theater(
private val ticketSeller: TicketSeller,
) {
fun enter(audience: Audience) {
ticketSeller.sellTo(audience)
}
}
5 changes: 5 additions & 0 deletions src/main/kotlin/kms/chapter01/Ticket.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kms.chapter01

internal class Ticket(
val fee: Long = 0,
)
31 changes: 31 additions & 0 deletions src/main/kotlin/kms/chapter01/TicketOffice.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package kms.chapter01

import kotlin.collections.ArrayList

internal class TicketOffice constructor(
private var amount: Long = 0L,
private val tickets: MutableList<Ticket> = ArrayList(),
) {
constructor(amount: Long, vararg tickets: Ticket) : this(
amount,
ArrayList<Ticket>().apply {
addAll(tickets.toList())
},
)

fun getTicket(): Ticket? {
return if (tickets.isNotEmpty()) {
tickets.removeAt(0)
} else {
null
}
}

fun minusAmount(amount: Long) {
this.amount = this.amount - amount
}

fun plusAmount(amount: Long) {
this.amount = this.amount + amount
}
}
14 changes: 14 additions & 0 deletions src/main/kotlin/kms/chapter01/TicketSeller.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package kms.chapter01

internal class TicketSeller(
private val ticketOffice: TicketOffice,
) {

fun sellTo(audience: Audience) {
val ticket = ticketOffice.getTicket()
if (ticket != null) {
val amount = audience.buy(ticket)
ticketOffice.plusAmount(amount)
}
}
}