算法计算得分

时间:2016-11-21 02:58:23

标签: algorithm

My progress score bar

我有一个像图片和5个部分的分数,包括A,B,C,D,E

A部分,我有10个得分与1星相匹配。 B部分,我有2个得分与2个星和C部分匹配,40个得分匹配3个星......当我收到3颗星时,我有70个分数。我需要帮助,当我有分数时,我需要调整白色条形图以正确匹配我的分数,任何帮助?

1 个答案:

答案 0 :(得分:1)

final int barSize = 600;
double barPercent;
double score = getScore();
// Assumed every section is 20% of barPercent
if (score >= 0 && score <= 10){
    barPercent = score / 10 * 20;
}else if (score > 10 && score <= 30){
    barPercent = 20 + (score - 10) / 20 * 20;
}else if (score > 30 && score <= 70){
    barPercent = 40 + (score - 30) / 40 * 20;
}else {...}

int result = barSize * barPercent / 100;
return result;

// test case:
// 50 score => bar=50 => result=300

希望有所帮助