FileDocCategorySizeDatePackage
PollBean.javaAPI DocExample2165Tue Feb 28 11:34:06 GMT 2006com.ora.jsp.beans.poll

PollBean

public class PollBean extends Object
This class maintains a list of answers in an online poll application. It's only intended as an example.
author
Hans Bergsten, Gefion software
version
1.0

Fields Summary
private int
total
private int
answer1
private int
answer2
private int
answer3
Constructors Summary
Methods Summary
public intgetAnswer1()
Returns the number of alternative 1 answers.

        return answer1;
    
public intgetAnswer1Percent()
Returns the percentage of alternative 1 answers.

        return getPercent(total, answer1);
    
public intgetAnswer2()
Returns the number of alternative 2 answers.

        return answer2;
    
public intgetAnswer2Percent()
Returns the percentage of alternative 2 answers.

        return getPercent(total, answer2);
    
public intgetAnswer3()
Returns the number of alternative 3 answers.

        return answer3;
    
public intgetAnswer3Percent()
Returns the percentage of alternative 3 answers.

        return getPercent(total, answer3);
    
private intgetPercent(int total, int answer)
Returns an int representing the rounded percentage of answers.

        return (int) Math.round(((double) answer / (double) total) * 100);
    
public intgetTotal()
Returns the total number of answers.

        return total;
    
public voidsetAnswer(AnswerBean answer)
Increments the counter matching the answer as well as the total number of answers.

        total++;
        String answerId = answer.getAnswerId();
        if (answerId.equals("1")) {
            answer1++;
        }
        else if (answerId.equals("2")) {
            answer2++;
        }
        else if (answerId.equals("3")) {
            answer3++;
        }