投票管理系统.docx
- 文档编号:9575726
- 上传时间:2023-02-05
- 格式:DOCX
- 页数:26
- 大小:327KB
投票管理系统.docx
《投票管理系统.docx》由会员分享,可在线阅读,更多相关《投票管理系统.docx(26页珍藏版)》请在冰豆网上搜索。
投票管理系统
投票管理系统
1题目描述
投票选举过程:
(1)用户从键盘输入候选人的个数(提示用户输入人数为1—12)、当选标准(例:
若为50%,只需输入50即可).点击确定后,由用户从键盘输入每一个候选人的姓名,提交后即可生成候选人的信息(包括姓名和编号).
(2)投票者就开始投票,对投票者没有姓名和编号的存储,只有结果的存储。
(3)以表格的形式展示选举结果,包括:
候选者的编号、姓名、所得票数、得票率、是否中选,并附投票人的个数和当选标准.
2类设计
2。
1类图
Manager:
控制整个系统,并对投票结果以及是否当选进行控制;
UserInterface:
控制整个系统的展示;
MainGraph:
接收候选者人数、姓名、当选标准信息;
VoteGraph:
接受用户的投票信息;
ResultGraph:
展示最终的投票结果;
Candidate:
候选人的实体对象,包括候选人的各种属性;
2。
2类声明
本报告采用java编程语言,一共构造了六个类:
1、Candidate;2、Manager;3、UserInterface;4、MainGraph;5、VoteGraph;6、ResultGraph.
2.2。
1、候选者类:
Candidate
publicclassCandidate{
privateStringname;//候选者姓名
privateintid;//候选者的编号
privateintnum;//得票数量
privatedoublevoteResult;//得票率
privatebooleanisVote;//是否中选
Candidate(Stringname,intid);//Candidate的构造方法
publicStringgetName();
publicvoidsetName(Stringname);
publicintgetId();
publicvoidsetId(intid);
publicintgetNum();
publicvoidsetNum(intnum);
publicdoublegetVoteResult();
publicvoidsetVoteResult(doublevoteResult);
publicbooleanisVote();
publicvoidsetVote(booleanisVote);
}
2。
2.2、管理类:
Manager类
publicclassManager{
publicintcandidates;//候选人的数量
publicintpercentage;//当选标准(百分比)
publicintvoters=0;//投票人数量
List〈Candidate〉listc;//装载候选者的容器
publicstaticvoidmain(String[]args);
publicvoidcalculateResult();//计算结果
}
2.2。
3、窗口的操作类UserInterface
publicclassUserInterfaceextendsJFrame{
privatestaticfinallongserialVersionUID=1L;
publicContainercontentPanel;//当前界面控制器
publicManagermanager;//利于数据通信,主要包括:
候选人数量、当选标准、投票者数量
publicJPanelp1;//输入信息的面板
publicJPanelp2;//投票面板
publicJPanelp3;//显示投票结果的面板
publicList publicList publicUserInterface(Managerm); publicvoidupdate();//窗口中增删组建后立即更新 publicvoidaddCandi(intnum);//panel1输入侯选者姓名完成后,生成候选者对象 } 2。 2。 4、输入面板类: MainGraph publicclassMainGraph{ privateUserInterfaceuserInterface;//与主面板的通信 publicMainGraph(UserInterfaceuserInterface);//MainGraph的构造函数 publicvoidlaunchMainGraph();//加载主面板 } 2。 2。 5、投票面板类: VoteGraph publicclassVoteGraph{ privateUserInterfaceuserInterface;//与主面板的通信 publicVoteGraph(UserInterfaceuserInterface);//构造函数 publicvoidlaunchVoteGraph();//加载投票面板 } 2。 2。 6、显示结果类: ResultGraph publicclassResultGraph{ privateUserInterfaceuserInterface;//与主面板的通信 publicResultGraph(UserInterfaceuserInterface);//构造函数 publicvoidlaunchResultGraph();//加载显示结果的面板 } 3功能实现 3。 1窗口显示 点击运行后弹出一个窗口(Panel1),要求用户输入候选人的个数(1-12)以及当选标准(若为50%,只需输入50即可) 假若依次输入12,50。 点击确定后,窗口中会提示输入侯选人的姓名,候选人的编号是从小到大依次生成的。 依次输入12人的姓名点击提交后,就会弹出投票的窗口 假若共有7名投票人参与投票(每次投票完点击提交即为完成依次投票)投票过程如下: 投票者1: 1号: 吴红岩3号: 邵芳9号: 李丹11号: 李四 投票者2: 2号: 刘莉莉3号: 邵芳4号: 尹聪敏6号: 王小丽 8号: 王永霞 投票者3: 1号: 吴红岩2号: 刘莉莉4号: 尹聪敏5号: 张三 7号: 李泽9号: 李丹 投票者4: 1号: 吴红岩7号: 李泽12号: 王龙贺 投票者5: 3号: 邵芳4号: 尹聪敏5号: 张三7号: 李泽 10号: 王小慧 投票者6: 1号: 吴红岩2号: 刘莉莉4号: 尹聪敏5号: 张三 10号: 王小慧11号: 李四12号: 王龙贺 投票者7: 1号: 吴红岩2号: 刘莉莉3号: 邵芳4号: 尹聪敏 7号: 李泽 最终的投票结果如下图所示: 3。 2功能1 整个系统的UML时序图如下图所示: 附录: 程序源代码 1、Candidate的详细代码: publicclassCandidate{ privateStringname;//候选者姓名 privateintid;//候选者的编号 privateintnum;//得票数量 privatedoublevoteResult;//得票率 privatebooleanisVote;//是否中选 Candidate(Stringname,intid){ this。 name=name; this.id=id; this。 num=0; this.voteResult=0; this。 isVote=false; } publicStringgetName(){ returnname; } publicvoidsetName(Stringname){ this.name=name; } publicintgetId(){ returnid; } publicvoidsetId(intid){ this。 id=id; } publicintgetNum(){ returnnum; } publicvoidsetNum(intnum){ this.num=num; } publicdoublegetVoteResult(){ returnvoteResult; } publicvoidsetVoteResult(doublevoteResult){ this。 voteResult=voteResult; } publicbooleanisVote(){ returnisVote; } publicvoidsetVote(booleanisVote){ this。 isVote=isVote; } publicStringtoString(){ returnthis.name; } } 2、Manager类的详细代码 importjava。 util。 ArrayList; importjava。 util。 List; publicclassManager{ publicintcandidates;//候选人的数量 publicintpercentage;//当选标准(百分比) publicintvoters=0;//投票人数量 List publicstaticvoidmain(String[]args){ Managerm=newManager(); UserInterfaceui=newUserInterface(m); MainGraphmainGraph=newMainGraph(ui); mainGraph。 launchMainGraph(); } publicvoidcalculateResult(){ doubled; for(inti=0;i Candidatec=listc。 get(i); d=(double)c.getNum()/voters; c.setVoteResult((double)Math。 round(d*10000)/100); if(d〉=percentage*0.01){ c.setVote(true); } } } } 3、UserInterface类的详细代码: importjava。 awt.Color; importjava.awt.Container; importjava.awt。 Font; importjava。 awt.event.ActionEvent; importjava。 awt.event.ActionListener; importjava。 util。 ArrayList; importjava。 util.Iterator; importjava。 util。 List; importjava。 util.Vector; importjavax。 swing.JButton; importjavax.swing。 JFrame; importjavax。 swing。 JLabel; importjavax。 swing。 JPanel; importjavax.swing。 JRadioButton; importjavax。 swing。 JScrollPane; importjavax。 swing。 JTable; importjavax。 swing。 JTextField; importjavax.swing.SwingConstants; importjavax。 swing。 table。 DefaultTableCellRenderer; /** * *@authorwhy * */ publicclassUserInterfaceextendsJFrame{ privatestaticfinallongserialVersionUID=1L; publicContainercontentPanel;//当前界面控制器 publicManagermanager;//利于数据通信,主要包括: 候选人数量、当选标准、投票者数量 publicJPanelp1;//输入信息的面板 publicJPanelp2;//投票面板 publicJPanelp3;//显示投票结果的面板 publicList〈JTextField〉list_textfield=newArrayList〈JTextField〉(); publicList〈JRadioButton>list_jradiobutton=newArrayList〈JRadioButton〉(); publicUserInterface(Managerm){ super(”欢迎来到投票管理系统"); this.manager=m; this。 setVisible(true); this.setBounds(150,30,700,700); this。 setDefaultCloseOperation(JFrame。 EXIT_ON_CLOSE); this.setResizable(false); this。 setBackground(Color.black); contentPanel=this。 getContentPane(); } publicvoidupdate(){ this。 repaint(); this。 setVisible(true); } publicvoidaddCandi(intnum){ JTextFieldtext_name; JLabellabel_name; JButtonsubmit=newJButton("提交”); Stringss=”"; intx1=80,x2=200,y=150,w=150,h=20; intyy=y; for(inti=1;i<=num;i++){ if(y>=this。 getHeight()-250){ y=yy; x1=x1+300; x2=x2+300; } y+=50; text_name=newJTextField();//新建输入姓名的文本框 label_name=newJLabel(ss); label_name.setText("候选人"+i+”的姓名: ”); label_name。 setBounds(x1,y,w,h); text_name.setBounds(x2,y,w,h); list_textfield.add(text_name);//把输入姓名的文本框加入到list中 p1。 add(label_name); p1.add(text_name); this。 update(); } submit。 setBounds(this。 getWidth()/3,this。 getHeight()—150,100,20); submit.addActionListener(newActionListener(){ publicvoidactionPerformed(ActionEvente){ for(inti=0;i〈list_textfield.size();i++){ Stringname=list_textfield。 get(i).getText();//得到文本框中输入的候选者姓名 Candidatecandi=newCandidate(name,i+1);//根据输入的姓名生成一个候选者 manager.listc。 add(candi);//把候选者加入到list中 } VoteGraphvoteGraph=newVoteGraph(UserInterface。 this); voteGraph.launchVoteGraph();//加载投票面板(Panel2) } }); p1.add(submit); } } 4、MainGraph类的详细代码: importjava。 awt。 Color; importjava。 awt。 Container; importjava。 awt。 Font; importjava。 awt。 HeadlessException; importjava。 awt。 event。 ActionEvent; importjava。 awt.event。 ActionListener; importjavax.swing.JButton; importjavax。 swing。 JLabel; importjavax.swing。 JPanel; importjavax.swing。 JTextField; /** *系统的主界面,接受候选者人数,以及当选的标准 *@authorwhy * */ publicclassMainGraph{ privateUserInterfaceuserInterface;//与主面板的通信 publicMainGraph(UserInterfaceuserInterface){ super(); this。 userInterface=userInterface; } publicvoidlaunchMainGraph(){ userInterface.p1=newJPanel(); userInterface.p1.setLayout(null); userInterface。 p1。 setBackground(Color.orange); userInterface。 contentPanel.add(userInterface。 p1); JLabellab=newJLabel(”请输入投票信息"); lab。 setBounds(200,30,250,50); intsize=25; lab。 setFont(newFont("Serif”,Font.PLAIN,size)); JLabellabel=newJLabel(”请输入候选人的个数(1—12): ”); finalJTextFieldtext=newJTextField();//输入候选人的个数 JLabellabelp=newJLabel(”请输当选标准(百分比): ”); finalJTextFieldpertage=newJTextField();//输入当选百分比 JButtonb=newJButton("确定”);//对候选人个数与百分比进行计较的按钮 label。 setBounds(80,100,170,20); labelp.setBounds(80,130,150,20); text。 setBounds(240,100,150,20); pertage.setBounds(240,130,150,20); b。 setBounds(500,130,70,20); b。 addActionListener(newActionListener(){ publicvoidactionPerformed(ActionEvente){ userInterface.manager.candidates=Integer.parseInt(text。 getText());//得到候选者的个数 userInterface。 addCandi(userInterface。 manager。 candidates); userInterface。 manager.percentage=Integer。 parseInt(pertage.getText());//得到当选百分比 } }); userInterface。 p1.add(label); userInterface.p1。 add(lab); userInterface.p1.add(text); userInterface。 p1。 add(b); userInterface。 p1。 add(labelp); userInterface。 p1。 add(pertage); userInterface。 update(); } } 5、VoteGraph类的详细代码: importjava。 awt。 Color; importjava.awt.Font; importjava。 awt.event。 ActionEvent; importjava。 awt。 event.ActionListener; importjava.util.Iterator; importjavax.swing。 JButton; importjavax.swing。 JLabel; importjavax.swing。 JPanel; importjavax。 swing。 JRadioButton; publicclassVoteGraph{ privateUserInterfaceuserInterface;//与主面板的通信 publicVoteGraph(UserInterfaceuserInterface){ super(); this。 userInterf
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 投票 管理 系统