Skip to content

Instantly share code, notes, and snippets.

@TonyHaddad91
Last active July 25, 2017 01:51
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 TonyHaddad91/8af44415fb811ad976edd5b3e8934759 to your computer and use it in GitHub Desktop.
Save TonyHaddad91/8af44415fb811ad976edd5b3e8934759 to your computer and use it in GitHub Desktop.
class Book(var numOfPages: Int, var pagePrice: Int=0, var type: Type = Type.SOFT_COPY) {
init {
if(numOfPages<=0)
throw RuntimeException("Number of pages must be more than zero")
}
fun calculateBookPrice(): Int {
var price: Int = numOfPages * pagePrice
if (type == Type.HARD_COPY)
price += 20
return price
}
fun isACookBook(): Boolean {
return numOfPages <= 200
}
}
enum class Type {
HARD_COPY, SOFT_COPY
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment