-
-
Save TonyHaddad91/8af44415fb811ad976edd5b3e8934759 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
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