JAVA投票管理程序编写

编写一个班级推荐优秀学生干部的投票管理程序。列出参与推荐的学生名单(6名),可以勾选进行投票,每个参选学生前面有图标表示候选人的职务,每人可以投3票,每次投票后能够显示当前投票人数以及每名候选者得票数,图形化柱状图显示得票数,可以保存投票结果到文本文件。请提供完整程序代码以及运行结果截图

public class VoteOperate {
private Person[] per = {new Person("小张",001,0),new Person("小王",002,0), new Person("小夏",003,0),
new Person("丁丁",004,0),new Person("刘强",005,0),new Person("小赵",006,0)};

private InputData input ;
private boolean flag = true;
private int sum;
private int errorVote;

public VoteOperate()
{
    this.input =  new InputData();
    while(flag)
    {
        ++sum;
        this.voteForCandidate();
    }
    this.printInfo();
    this.getResulet();
}
public class VoteOperate {
    private Person[] per = {new Person("小张",001,0),new Person("小王",002,0), new Person("小夏",003,0),
        new Person("丁丁",004,0),new Person("刘强",005,0),new Person("小赵",006,0)};

    private InputData input ;
    private boolean flag = true;
    private int sum;
    private int errorVote;

    public VoteOperate()
    {
        this.input =  new InputData();
        while(flag)
        {
            ++sum;
            this.voteForCandidate();
        }
        this.printInfo();
        this.getResulet();
    }

import java.util.Scanner;

public class OneTest {

@SuppressWarnings({ "resource",})

public static void main(String[] args) {

Candidate[] candidates={new Candidate("张三",1,0),new Candidate("李四",2,0),new Candidate("王五",3,0),new Candidate("赵六",4,0)};

System.out.println("1:张三【0票】");

System.out.println("2:李四【0票】");

System.out.println("3:王五【0票】");

System.out.println("4:赵六【0票】");

Scanner intScanner=new Scanner(System.in);

System.out.print("请输入班长候选人代号(数字0结束):");

String numStr=intScanner.nextLine();

boolean isNum=false;

do{

//System.out.println("输入的内容是:"+intScanner.next());

try{

int num=Integer.valueOf(numStr);

isNum=true;

if(num==0){

break;

}else if(num==1){

candidates[0].setBallot(candidates[0].getBallot()+1);

}else if(num==2){

candidates[1].setBallot(candidates[1].getBallot()+1);

}else if(num==3){

candidates[2].setBallot(candidates[2].getBallot()+1);

}else if(num==4){

candidates[3].setBallot(candidates[3].getBallot()+1);

}else{

System.out.println("此选票无效,请输入正确的候选人代号!");

}

System.out.print("请输入班长候选人代号(数字0结束):");

numStr=intScanner.nextLine();

} catch (Exception e) {

System.out.println("此选票无效http://www.aivote.com请输入正确的候选人代号!");

System.out.print("请输入班长候选人代号(数字0结束):");

numStr=intScanner.nextLine();

main(args);

}

}while (isNum);

System.out.println("张三:"+candidates[0].getBallot()+"票");

System.out.println("李四:"+candidates[1].getBallot()+"票");

System.out.println("王五:"+candidates[2].getBallot()+"票");

System.out.println("赵六:"+candidates[3].getBallot()+"票");

Candidate tempcaCandidate=candidates[0];

for(int i=0;i<candidates.length-1;i++){

if(candidates[i].getBallot()<candidates[i+1].getBallot()){

tempcaCandidate=candidates[i+1];

}

}

System.out.print(tempcaCandidate.getSymbol());

System.out.print(":"+tempcaCandidate.getName());

System.out.print(":"+tempcaCandidate.getBallot()+"票");

}

}

Candidate候选人对象

package Candidate;

public class Candidate {

private String name;

private int symbol;

private int ballot;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getSymbol() {

return symbol;

}

public void setSymbol(int symbol) {

this.symbol = symbol;

}

public int getBallot() {

return ballot;

}

public void setBallot(int ballot) {

this.ballot = ballot;

}

public Candidate(){}

public Candidate(String name, int symbol, int ballot) {

super();

this.name = name;

this.symbol = symbol;

this.ballot = ballot;