Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case class Customer(name: String, private var cash: Int) {
- def buy(price: Int): Unit = {
- if(canBuy(price))
- cash -= price
- }
- def canBuy: Int => Boolean = _ <= cash
- }
- class Applestore(capacity: Int, itemsCount: Int) {
- private var customersWaiting: Array[Customer] = new Array[Customer](capacity)
- private var price: Int = 900
- private var serveTime: Int = 60
- private var pointer: Int = 0
- def canEnqueue: Boolean = pointer < capacity
- def canServe: Boolean = itemsCount > 0
- def countQueue: Int = pointer
- def timeGetServed(customer: Customer): Int = customersWaiting.indexOf(customer) * 60
- def enqueue(customer: Customer): Unit = {
- if(!canEnqueue)
- return
- customersWaiting(pointer) = customer
- pointer += 1
- }
- def serve: Unit = {
- if(!canServe)
- return
- val customer = customersWaiting.head
- if(customer.canBuy(price))
- customer.buy(price)
- customersWaiting = customersWaiting.tail :+ null
- pointer -= 1
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement