jeudi 20 septembre 2018

Implementing a matrix of prices for different types

Membership      || interest rate
Gold            || 0.12, 0.20, 0.3
Silver          || 0.13, 0.24, 0.3
Bronze          || 10.1, 0.2, 0.3

Membership      || value rate
Gold            || 10, 20, 30
Silver          || 10, 50, 40

In my app, I have some membership types. I want to calculate in advance all possible price combinations of the above and present in one object for each membership.

Let's say a user chooses Gold membership, I am looking to calculate every combination of (value x interest rate) and present to user in some object..

How can I implement this and what data structures, design can I use?

A user can select multiple membership if they wish in which case it should present all value/rate combination for both memberships.

I have something like this for example:

sealed class MembershipType(val label: String) {

    abstract val interestRates: List<BigDecimal>
    abstract val valueOptions: List<BigDecimal>


    object SILVER : MembershipType("Silver") {

        override val valueOptions: List<BigDecimal> =
                listOf<BigDecimal>(
                        BigDecimal.valueOf(10),
                        BigDecimal.valueOf(50),
                        BigDecimal.valueOf(40))
    }...

I have function that receives the list as follows:

fun calculateQuote(score: Int, memberShipSelected: List<MembershipType>): Quote {//TODO}

For each membership type in list, extract the value and rate and calculate all possible combinations.

Aucun commentaire:

Enregistrer un commentaire