Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (30 sloc) 975 Bytes
package com.example.kylejablonski.mvpdemo
class MainModel {
val tipOptions = arrayOf(5, 10, 15, 20, 22)
val defaultTipIndex = 3
private var selectedTipOption = tipOptions[defaultTipIndex]
var checkAmount = 0.00
var totalAmount = 0.00
var tipAmount = 0.00
fun setTipOption(position: Int) {
// default tip to lowest option
selectedTipOption = if (position < 0 || position >= tipOptions.size) {
tipOptions[defaultTipIndex]
} else {
tipOptions[position]
}
}
fun computeTotalPrice(price: String?): Double {
if(price.isNullOrEmpty()){
return 0.00
}
val doublePrice = price!!.toDouble()
if (doublePrice < 0) {
return totalAmount
}
checkAmount = doublePrice
tipAmount = checkAmount * (selectedTipOption.toDouble() / 100)
totalAmount = checkAmount + tipAmount
return totalAmount
}
}
You can’t perform that action at this time.