Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoulongkam committed Mar 18, 2020
1 parent fbdb555 commit 286250a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,47 @@ package uk.gov.hmrc.helptosavecalculator
import uk.gov.hmrc.helptosavecalculator.models.FirstBonusInput
import uk.gov.hmrc.helptosavecalculator.utils.monthsSince

open class FirstBonusTermCalculation {
internal class FirstBonusTermCalculation {

protected fun calculateTotalProjectedSavingsIncludeBonuses(
fun calculateTotalProjectedSavingsIncludeBonuses(
totalProjectedSavings: Double,
totalProjectedBonuses: Double
): Double {
return totalProjectedSavings + totalProjectedBonuses
}

protected fun calculateAdditionalSavingsThisMonth(input: FirstBonusInput): Double {
fun calculateAdditionalSavingsThisMonth(input: FirstBonusInput): Double {
return if (input.regularPayment > input.paidInThisMonth) {
input.regularPayment - input.paidInThisMonth
} else {
0.0
}
}

protected fun calculateTotalProjectedSavings(
fun calculateTotalProjectedSavings(
input: FirstBonusInput,
additionalSavingsThisMonth: Double,
monthsLeftInScheme: Int
): Double {
return input.currentBalance + additionalSavingsThisMonth + (input.regularPayment * monthsLeftInScheme)
}

protected fun calculateTotalProjectedBonuses(
fun calculateTotalProjectedBonuses(
projectedFirstBonus: Double,
projectedFinalBonus: Double
): Double {
return projectedFirstBonus + projectedFinalBonus
}

protected fun calculateProjectedSavingsFirstBonusPeriod(
fun calculateProjectedSavingsFirstBonusPeriod(
input: FirstBonusInput,
additionalSavingsThisMonth: Double,
monthsLeftInFirstTerm: Int
): Double {
return input.currentBalance + additionalSavingsThisMonth + (input.regularPayment * monthsLeftInFirstTerm)
}

protected fun calculateHighestBalanceFirstBonusPeriod(
fun calculateHighestBalanceFirstBonusPeriod(
input: FirstBonusInput,
projectedSavingsFirstBonusPeriod: Double
): Double {
Expand All @@ -67,15 +67,15 @@ open class FirstBonusTermCalculation {
} ?: projectedSavingsFirstBonusPeriod
}

protected fun calculateProjectedFirstBonus(highestBalanceFirstBonusPeriod: Double): Double {
fun calculateProjectedFirstBonus(highestBalanceFirstBonusPeriod: Double): Double {
return highestBalanceFirstBonusPeriod / 2
}

protected fun calculateProjectedAdditionalSavingsFinalBonusPeriod(input: FirstBonusInput): Double {
fun calculateProjectedAdditionalSavingsFinalBonusPeriod(input: FirstBonusInput): Double {
return input.regularPayment * 24
}

protected fun calculateProjectedFinalBonus(
fun calculateProjectedFinalBonus(
highestBalanceFinalBonusPeriod: Double,
highestBalanceFirstBonusPeriod: Double
): Double {
Expand All @@ -86,7 +86,7 @@ open class FirstBonusTermCalculation {
}
}

protected fun calculateMonthsLeftInScheme(input: FirstBonusInput): Pair<Int, Int> {
fun calculateMonthsLeftInScheme(input: FirstBonusInput): Pair<Int, Int> {
val startDate = input.accountStartDate.convertToDateTime()
val secondTermEndDate = input.secondTermEndDate.convertToDateTime()
val firstTermEndDate = input.firstTermEndDate.convertToDateTime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import uk.gov.hmrc.helptosavecalculator.models.FirstBonusCalculatorResponse
import uk.gov.hmrc.helptosavecalculator.models.FirstBonusInput
import uk.gov.hmrc.helptosavecalculator.validation.RegularPaymentValidators

object FirstBonusTermCalculator : FirstBonusTermCalculation() {
object FirstBonusTermCalculator {

private val calculation = FirstBonusTermCalculation()

fun runFirstBonusCalculator(input: FirstBonusInput): FirstBonusCalculatorResponse {
return calculateFirstBonus(input)
Expand All @@ -29,19 +31,25 @@ object FirstBonusTermCalculator : FirstBonusTermCalculation() {
private fun calculateFirstBonus(input: FirstBonusInput): FirstBonusCalculatorResponse {
validateUserInput(input.regularPayment)

val (monthLeftInScheme, monthLeftInFirstTerm) = calculateMonthsLeftInScheme(input)
val additionalSavingsThisMonth = calculateAdditionalSavingsThisMonth(input)
val totalProjectedSavings = calculateTotalProjectedSavings(input, additionalSavingsThisMonth, monthLeftInScheme)
val projectedSavingsFirstBonusPeriod = calculateProjectedSavingsFirstBonusPeriod(input,
val (monthLeftInScheme, monthLeftInFirstTerm) = calculation.calculateMonthsLeftInScheme(input)
val additionalSavingsThisMonth = calculation.calculateAdditionalSavingsThisMonth(input)
val totalProjectedSavings = calculation.calculateTotalProjectedSavings(input,
additionalSavingsThisMonth,
monthLeftInScheme)
val projectedSavingsFirstBonusPeriod = calculation.calculateProjectedSavingsFirstBonusPeriod(input,
additionalSavingsThisMonth,
monthLeftInFirstTerm)
val highestBalanceFirstBonusPeriod = calculateHighestBalanceFirstBonusPeriod(input,
val highestBalanceFirstBonusPeriod = calculation.calculateHighestBalanceFirstBonusPeriod(input,
projectedSavingsFirstBonusPeriod)
val projectedFirstBonus = calculateProjectedFirstBonus(highestBalanceFirstBonusPeriod)
val projectedAdditionalSavingsFinalBonusPeriod = calculateProjectedAdditionalSavingsFinalBonusPeriod(input)
val projectedFinalBonus = calculateProjectedFinalBonus(totalProjectedSavings, highestBalanceFirstBonusPeriod)
val totalProjectedBonuses = calculateTotalProjectedBonuses(projectedFirstBonus, projectedFinalBonus)
val totalProjectedSavingsIncludingBonuses = calculateTotalProjectedSavingsIncludeBonuses(totalProjectedSavings,
val projectedFirstBonus = calculation.calculateProjectedFirstBonus(highestBalanceFirstBonusPeriod)
val projectedAdditionalSavingsFinalBonusPeriod =
calculation.calculateProjectedAdditionalSavingsFinalBonusPeriod(input)
val projectedFinalBonus = calculation.calculateProjectedFinalBonus(totalProjectedSavings,
highestBalanceFirstBonusPeriod)
val totalProjectedBonuses = calculation.calculateTotalProjectedBonuses(projectedFirstBonus,
projectedFinalBonus)
val totalProjectedSavingsIncludingBonuses =
calculation.calculateTotalProjectedSavingsIncludeBonuses(totalProjectedSavings,
totalProjectedBonuses)

return FirstBonusCalculatorResponse(
Expand Down

0 comments on commit 286250a

Please sign in to comment.