Reputation: 55
I have a score like picture and 5 sections with A, B, C, D, E
Section A, I have 10 score match with 1 star. Section B, I have 20 score match with 2 star and section C with 40 score match with 3 star... When I receive 3 stars, I have 70 scores. I need help, when I have scores I need resize white bar to right match with score I have, any help ?
Upvotes: 0
Views: 363
Reputation: 517
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
hope it helps
Upvotes: 1