Skip to content

Instantly share code, notes, and snippets.

@vamsitallapudi
Created December 5, 2020 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vamsitallapudi/857fe571d4ba60bc2ac55ba7379f9b67 to your computer and use it in GitHub Desktop.
Save vamsitallapudi/857fe571d4ba60bc2ac55ba7379f9b67 to your computer and use it in GitHub Desktop.
package main.leetcode.kotlin
interface Hotel {
fun getPrice(): Int
}
class Mariott : Hotel {
private val basePrice = 2000
private val tax = 500
override fun getPrice(): Int {
return basePrice + tax
}
}
class Taj : Hotel {
private val basePrice = 3000
override fun getPrice(): Int {
return basePrice
}
}
class Hyatt : Hotel {
private val basePrice = 4000
private val parkingFee = 500
private val tax = 1000
override fun getPrice(): Int {
return basePrice + parkingFee + tax
}
}
class PriceFactory {
fun calculatePrices(hotels: List<Hotel>): Int {
var totalPrice = 0
hotels.forEach {
totalPrice += it.getPrice()
}
return totalPrice
}
}
fun main() {
print(PriceFactory().calculatePrices(listOf(Mariott(),Taj(),Hyatt())))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment