Jay Roy
asked on
generate percentage in java
hi guys
I have a requirment where user has 30 answers to fill in a UI form. The answers are then stored in a java object AnswerVO. finally the answers are stored in a list
List answerList = new ArrayList()
for int i=0; i< 30; i++
{
answerList.add(AnswerVO) --put all the answers in a list.
}
The answer is stored in AnswerVO
public Class AnswerVO {
public string answervalue;
set()
get()
}
Based on the number of answers filled out by users i have to generate a percentage.
any idea how best that can be done?
thanks
I have a requirment where user has 30 answers to fill in a UI form. The answers are then stored in a java object AnswerVO. finally the answers are stored in a list
List answerList = new ArrayList()
for int i=0; i< 30; i++
{
answerList.add(AnswerVO) --put all the answers in a list.
}
The answer is stored in AnswerVO
public Class AnswerVO {
public string answervalue;
set()
get()
}
Based on the number of answers filled out by users i have to generate a percentage.
any idea how best that can be done?
thanks
A percentage of what though?
If it's a percentage of the complete number of answers, it would be
double percent = n / 30.0 * 100; // (n is number of answers filled in)
ASKER
i have to check how many answers are NOT empty (meaning they are filled with answers) and then calcualte how many of the answers have been filled out of the 30 and generate a percentage completed
You probably check how many correct answers, say you have method
returning boolean for correct answer and then
something like that:
int count = 0;
for(int j=0; j<answerList.size(); j++){
AnswrVO aa = (AnswerVO)answerLits.get(j );
if(aa.correct())count++;
}
float percent = ((float)count/(float)answe rList.size ())*100.0
Sistem.out.println("Good answers: " + percent + "%");
returning boolean for correct answer and then
something like that:
int count = 0;
for(int j=0; j<answerList.size(); j++){
AnswrVO aa = (AnswerVO)answerLits.get(j
if(aa.correct())count++;
}
float percent = ((float)count/(float)answe
Sistem.out.println("Good answers: " + percent + "%");
Then you should hav ethe checck method if answer is responded
int count = 0;
for(int j=0; j<answerList.size(); j++){
AnswrVO aa = (AnswerVO)answerLits.get(j );
if(aa.getAnswerValue() != null)count++;
}
float percent = ((float)count/(float)answe rList.size ())*100.0
Sistem.out.println(" answers responded: " + percent + "%");
int count = 0;
for(int j=0; j<answerList.size(); j++){
AnswrVO aa = (AnswerVO)answerLits.get(j
if(aa.getAnswerValue() != null)count++;
}
float percent = ((float)count/(float)answe
Sistem.out.println(" answers responded: " + percent + "%");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:)