投票管理系統(tǒng)_第1頁
投票管理系統(tǒng)_第2頁
投票管理系統(tǒng)_第3頁
投票管理系統(tǒng)_第4頁
投票管理系統(tǒng)_第5頁
已閱讀5頁,還剩12頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、投票管理系統(tǒng)1 題目描述投票選舉過程:(1)用戶從鍵盤輸入候選人的個(gè)數(shù)(提示用戶輸入人數(shù)為1-12)、當(dāng)選標(biāo)準(zhǔn)(例:若為50%,只需輸入50即可)。點(diǎn)擊確定后,由用戶從鍵盤輸入每一個(gè)候選人的姓名,提交后即可生成候選人的信息(包括姓名和編號(hào))。(2)投票者就開始投票,對(duì)投票者沒有姓名和編號(hào)的存儲(chǔ),只有結(jié)果的存儲(chǔ)。(3)以表格的形式展示選舉結(jié)果,包括:候選者的編號(hào)、姓名、所得票數(shù)、得票率、是否中選,并附投票人的個(gè)數(shù)和當(dāng)選標(biāo)準(zhǔn)。2類設(shè)計(jì)2.1 類圖Manager:控制整個(gè)系統(tǒng),并對(duì)投票結(jié)果以及是否當(dāng)選進(jìn)行控制;UserInterface:控制整個(gè)系統(tǒng)的展示;MainGraph:接收候選者人數(shù)、姓名、

2、當(dāng)選標(biāo)準(zhǔn)信息;VoteGraph:接受用戶的投票信息;ResultGraph:展示最終的投票結(jié)果;Candidate:候選人的實(shí)體對(duì)象,包括候選人的各種屬性;2.2 類聲明本報(bào)告采用java編程語言,一共構(gòu)造了六個(gè)類:1、Candidate; 2、Manager; 3、UserInterface;4、MainGraph;5、VoteGraph ;6、ResultGraph。、候選者類:Candidatepublic class Candidate private String name;/候選者姓名private int id;/候選者的編號(hào)private int num; / 得票數(shù)量pri

3、vate double voteResult; /得票率private boolean isVote;/是否中選Candidate(String name, int id) ;/Candidate 的構(gòu)造方法public String getName() ;public void setName(String name) ;public int getId() ;public void setId(int id) ;public int getNum() ;public void setNum(int num) ;public double getVoteResult() ;public vo

4、id setVoteResult(double voteResult) ;public boolean isVote();public void setVote(boolean isVote) ;、管理類:Manager類public class Manager public int candidates; / 候選人的數(shù)量public int percentage; / 當(dāng)選標(biāo)準(zhǔn)(百分比)public int voters = 0; / 投票人數(shù)量List listc ;/ 裝載候選者的容器public static void main(String args) ;public void c

5、alculateResult() ;/ 計(jì)算結(jié)果 、窗口的操作類UserInterface public class UserInterface extends JFrame private static final long serialVersionUID = 1L;public Container contentPanel; / 當(dāng)前界面控制器public Manager manager; /利于數(shù)據(jù)通信,主要包括:候選人數(shù)量、當(dāng)選標(biāo)準(zhǔn)、投票者數(shù)量public JPanel p1; /輸入信息的面板public JPanel p2;/投票面板public JPanel p3;/顯示投票結(jié)

6、果的面板public List list_textfield ;/裝載候選人姓名的容器public List list_jradiobutton ;/投票public UserInterface(Manager m) ;public void update() ;/窗口中增刪組建后立即更新public void addCandi(int num);/panel1輸入侯選者姓名完成后,生成候選者對(duì)象 、輸入面板類:MainGraphpublic class MainGraphprivate UserInterface userInterface; /與主面板的通信public MainGraph

7、(UserInterface userInterface) ;/MainGraph的構(gòu)造函數(shù)public void launchMainGraph() ;/加載主面板、投票面板類:VoteGraph public class VoteGraph private UserInterface userInterface;/與主面板的通信public VoteGraph(UserInterface userInterface) ;/構(gòu)造函數(shù)public void launchVoteGraph();/加載投票面板、顯示結(jié)果類:ResultGraphpublic class ResultGraph p

8、rivate UserInterface userInterface;/與主面板的通信public ResultGraph(UserInterface userInterface) ;/構(gòu)造函數(shù)public void launchResultGraph() ;/加載顯示結(jié)果的面板3 功能實(shí)現(xiàn)3.1 窗口顯示點(diǎn)擊運(yùn)行后彈出一個(gè)窗口(Panel1),要求用戶輸入候選人的個(gè)數(shù)(1-12)以及當(dāng)選標(biāo)準(zhǔn)(若為50%,只需輸入50即可) 假若依次輸入12, 50.點(diǎn)擊確定后,窗口中會(huì)提示輸入侯選人的姓名,候選人的編號(hào)是從小到大依次生成的。依次輸入12人的姓名點(diǎn)擊提交后,就會(huì)彈出投票的窗口假若共有7名投票人

9、參與投票(每次投票完點(diǎn)擊提交即為完成依次投票)投票過程如下:投票者1:1號(hào):吳紅巖 3號(hào):邵芳 9號(hào):李丹 11號(hào):李四投票者2:2號(hào):劉莉莉 3號(hào):邵芳 4號(hào):尹聰敏 6號(hào):王小麗8號(hào):王永霞 投票者3:1號(hào):吳紅巖 2號(hào):劉莉莉 4號(hào):尹聰敏 5號(hào):張三7號(hào):李澤 9號(hào):李丹投票者4:1號(hào):吳紅巖 7號(hào):李澤 12號(hào):王龍賀 投票者5:3號(hào):邵芳 4號(hào):尹聰敏 5號(hào):張三 7號(hào):李澤10號(hào):王小慧投票者6:1號(hào):吳紅巖 2號(hào):劉莉莉 4號(hào):尹聰敏 5號(hào):張三10號(hào):王小慧 11號(hào):李四 12號(hào):王龍賀投票者7:1號(hào):吳紅巖 2號(hào):劉莉莉 3號(hào):邵芳 4號(hào):尹聰敏 7號(hào):李澤最終的投票結(jié)果如

10、下圖所示: 3.2 功能1整個(gè)系統(tǒng)的UML時(shí)序圖如下圖所示:附錄:程序源代碼1、Candidate 的詳細(xì)代碼:public class Candidate private String name;/候選者姓名private int id;/候選者的編號(hào)private int num; / 得票數(shù)量private double voteResult; /得票率private boolean isVote;/是否中選Candidate(String name, int id) = name;this.id = id;this.num = 0;this.voteResult =

11、 0;this.isVote = false;public String getName() return name;public void setName(String name) = name;public int getId() return id;public void setId(int id) this.id = id;public int getNum() return num;public void setNum(int num) this.num = num;public double getVoteResult() return voteResult;p

12、ublic void setVoteResult(double voteResult) this.voteResult = voteResult;public boolean isVote() return isVote;public void setVote(boolean isVote) this.isVote = isVote;public String toString() return ;2、 Manager類的詳細(xì)代碼import ;import ;public class Manager public int candidates; / 候選人的數(shù)量public

13、 int percentage; / 當(dāng)選標(biāo)準(zhǔn)(百分比)public int voters = 0; / 投票人數(shù)量List listc = new ArrayList();public static void main(String args) Manager m = new Manager();UserInterface ui = new UserInterface(m);MainGraph mainGraph = new MainGraph(ui);mainGraph.launchMainGraph();public void calculateResult() double d;for

14、 (int i = 0; i = percentage * 0.01) c.setVote(true);3、 UserInterface類的詳細(xì)代碼:import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;/* * * author why * */public class UserInterface extends JFrame private s

15、tatic final long serialVersionUID = 1L;public Container contentPanel; / 當(dāng)前界面控制器public Manager manager; /利于數(shù)據(jù)通信,主要包括:候選人數(shù)量、當(dāng)選標(biāo)準(zhǔn)、投票者數(shù)量public JPanel p1; /輸入信息的面板public JPanel p2;/投票面板public JPanel p3;/顯示投票結(jié)果的面板public List list_textfield = new ArrayList();public List list_jradiobutton = new ArrayList();

16、public UserInterface(Manager m) super(歡迎來到投票管理系統(tǒng));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();public void update() this.repai

17、nt();this.setVisible(true);public void addCandi(int num) JTextField text_name;JLabel label_name;JButton submit = new JButton(提交);String ss = ;int x1 = 80, x2 = 200, y = 150, w = 150, h = 20;int yy = y;for (int i = 1; i = this.getHeight() - 250) y = yy;x1 = x1 + 300;x2 = x2 + 300;y += 50;text_name =

18、new JTextField(); / 新建輸入姓名的文本框label_name = new JLabel(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, t

19、his.getHeight() - 150, 100, 20);submit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) for (int i = 0; i list_textfield.size(); i+) String name = list_textfield.get(i).getText(); / 得到文本框中輸入的候選者姓名Candidate candi = new Candidate(name, i + 1); / 根據(jù)輸入的姓名生成一個(gè)候選者manager.l

20、istc.add(candi); / 把候選者加入到list中VoteGraph voteGraph = new VoteGraph(UserInterface.this);voteGraph.launchVoteGraph(); / 加載投票面板(Panel2);p1.add(submit);4、 MainGraph類的詳細(xì)代碼:import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;/* * 系統(tǒng)的主界面,接受候選者人數(shù),以及當(dāng)選的標(biāo)準(zhǔn) * author why * */public c

21、lass MainGraphprivate UserInterface userInterface; /與主面板的通信public MainGraph(UserInterface userInterface) super();this.userInterface = userInterface;public void launchMainGraph() userInterface.p1 = new JPanel();userInterface.p1.setLayout(null);userInterface.p1.setBackground(Color.orange);userInterfac

22、e.contentPanel.add(userInterface.p1);JLabel lab = new JLabel(請(qǐng)輸入投票信息);lab.setBounds(200, 30, 250, 50);int size = 25;lab.setFont(new Font(Serif, Font.PLAIN, size);JLabel label = new JLabel(請(qǐng)輸入候選人的個(gè)數(shù)(1-12):);final JTextField text = new JTextField(); / 輸入候選人的個(gè)數(shù)JLabel labelp = new JLabel(請(qǐng)輸當(dāng)選標(biāo)準(zhǔn)(百分比):);f

23、inal JTextField pertage = new JTextField(); / 輸入當(dāng)選百分比JButton b = new JButton(確定); / 對(duì)候選人個(gè)數(shù)與百分比進(jìn)行計(jì)較的按鈕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(new Actio

24、nListener() public void actionPerformed(ActionEvent e) userInterface.manager.candidates = Integer.parseInt(text.getText(); / 得到候選者的個(gè)數(shù)userInterface.addCandi(userInterface.manager.candidates);userInterface.manager.percentage = Integer.parseInt(pertage.getText(); / 得到當(dāng)選百分比);userInterface.p1.add(label);

25、userInterface.p1.add(lab);userInterface.p1.add(text);userInterface.p1.add(b);userInterface.p1.add(labelp);userInterface.p1.add(pertage);userInterface.update();5、 VoteGraph類的詳細(xì)代碼:import ;import ;import ;import ;import ;import ;import ;import ;import ;public class VoteGraph private UserInterface userI

26、nterface;/與主面板的通信public VoteGraph(UserInterface userInterface) super();this.userInterface = userInterface;public void launchVoteGraph() userInterface.list_jradiobutton.clear();int x = 80, y = 150, w = 120, h = 20;int yy = y;JRadioButton jrb;userInterface.contentPanel.removeAll();userInterface.p2 = n

27、ew JPanel();userInterface.contentPanel.add(userInterface.p2);userInterface.p2.setLayout(null);userInterface.p2.setBackground(Color.orange);JLabel label = new JLabel(請(qǐng)為候選者投票);label.setBounds(200, 100, 250, 50);int size = 25;label.setFont(new Font(Serif, Font.PLAIN, size);JButton voter_submit = new JB

28、utton(提交);voter_submit.setBounds(100, userInterface.getHeight() - 150, 100, 20);voter_submit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) userInterface.manager.voters+;for (int i = 0; i userInterface.manager.candidates; i+) if (userInterface.list_jradiobutton.get

29、(i).isSelected() userInterface.manager.listc.get(i).setNum(userInterface.manager.listc.get(i).getNum() + 1);userInterface.contentPanel.remove(userInterface.p2);launchVoteGraph();userInterface.update(););JButton result_submit = new JButton(顯示結(jié)果);result_submit.setBounds(370, userInterface.getHeight()

30、- 150, 100, 20);result_submit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) userInterface.manager.calculateResult();ResultGraph result = new ResultGraph(userInterface);result.launchResultGraph();userInterface.update(););Iterator iterator = userInterface.manager.li

31、stc.iterator();for (int i = 1; i = userInterface.getHeight() - 250) y = yy;x = x + 300;y += 50;jrb = new JRadioButton(i + 號(hào): + cand.getName();jrb.setBounds(x, y, w, h);userInterface.list_jradiobutton.add(jrb);userInterface.p2.add(jrb);userInterface.update();userInterface.p2.add(voter_submit);userInt

32、erface.p2.add(result_submit);userInterface.p2.add(label);userInterface.contentPanel.add(userInterface.p2);userInterface.update();6、 ResultGraph類的詳細(xì)代碼:import ;import ;import ;import ;import ;import ;import ;import ;public class ResultGraph private UserInterface userInterface;/與主面板的通信public ResultGrap

33、h(UserInterface userInterface) super();this.userInterface = userInterface;public void launchResultGraph() JLabel label = new JLabel(最終結(jié)果);label.setBounds(300, 50, 250, 50);int size = 25;label.setFont(new Font(Serif, Font.PLAIN, size);JLabel la = new JLabel(共有 + userInterface.manager.voters + 個(gè)投票人 當(dāng)選

34、標(biāo)準(zhǔn):+ userInterface.manager.percentage + %);la.setBounds(200, 570, 250, 50);int si = 15;la.setFont(new Font(Serif, Font.PLAIN, si);JScrollPane scrollPane = new JScrollPane(); / 支持滾動(dòng)scrollPane.setBounds(100, 150, 500, 380);String columnNames = 候選者編號(hào), 姓名, 票數(shù), 得票率, 是否中選 ;Vector columnNameV = new Vector(); / 獲得表頭for (int column = 0; column 5; column+) columnNa

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論