⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pollbean.java

📁 大家好啊 快来抢购J2ME东东 挺不错的啊 不要后悔啊 抓住机会
💻 JAVA
字号:
package com.ora.jsp.beans.poll;

import java.math.*;

/**
 * This class maintains a list of answers in an online poll
 * application. It's only intended as an example.
 *
 * @author Hans Bergsten, Gefion software <hans@gefionsoftware.com>
 * @version 1.0
 */
public class PollBean {
    private int total;
    private int answer1;
    private int answer2;
    private int answer3;
    
    /**
     * Increments the counter matching the answer as well
     * as the total number of answers.
     */
    public void setAnswer(AnswerBean answer) {
        total++;
        String answerId = answer.getAnswerId();
        if (answerId.equals("1")) {
            answer1++;
        }
        else if (answerId.equals("2")) {
            answer2++;
        }
        else if (answerId.equals("3")) {
            answer3++;
        }
    }
    
    /**
     * Returns the total number of answers.
     */
    public int getTotal() {
        return total;
    }
    
    /**
     * Returns the number of alternative 1 answers.
     */
    public int getAnswer1() {
        return answer1;
    }
    
    /**
     * Returns the number of alternative 2 answers.
     */
    public int getAnswer2() {
        return answer2;
    }
    
    /**
     * Returns the number of alternative 3 answers.
     */
    public int getAnswer3() {
        return answer3;
    }
    
    /**
     * Returns the percentage of alternative 1 answers.
     */
    public int getAnswer1Percent() {
        return getPercent(total, answer1);
    }
    
    /**
     * Returns the percentage of alternative 2 answers.
     */
    public int getAnswer2Percent() {
        return getPercent(total, answer2);
    }
    
    /**
     * Returns the percentage of alternative 3 answers.
     */
    public int getAnswer3Percent() {
        return getPercent(total, answer3);
    }
 
    /**
     * Returns an int representing the rounded percentage of
     * answers.
     */
    private int getPercent(int total, int answer) {
        return (int) Math.round(((double) answer / (double) total) * 100);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -