Created
December 5, 2020 05:27
-
-
Save vamsitallapudi/857fe571d4ba60bc2ac55ba7379f9b67 to your computer and use it in GitHub Desktop.
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
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