




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、投票管理系統(tǒng)1 題目描述投票選舉過程:(1)用戶從鍵盤輸入候選人的個數(shù)(提示用戶輸入人數(shù)為1-12)、當(dāng)選標(biāo)準(zhǔn)(例:若為50%,只需輸入50即可)。點(diǎn)擊確定后,由用戶從鍵盤輸入每一個候選人的姓名,提交后即可生成候選人的信息(包括姓名和編號)。(2)投票者就開始投票,對投票者沒有姓名和編號的存儲,只有結(jié)果的存儲。(3)以表格的形式展示選舉結(jié)果,包括:候選者的編號、姓名、所得票數(shù)、得票率、是否中選,并附投票人的個數(shù)和當(dāng)選標(biāo)準(zhǔn)。2類設(shè)計(jì)2.1 類圖Manager:控制整個系統(tǒng),并對投票結(jié)果以及是否當(dāng)選進(jìn)行控制;UserInterface:控制整個系統(tǒng)的展示;MainGraph:接收候選者人數(shù)、姓名、
2、當(dāng)選標(biāo)準(zhǔn)信息;VoteGraph:接受用戶的投票信息;ResultGraph:展示最終的投票結(jié)果;Candidate:候選人的實(shí)體對象,包括候選人的各種屬性;2.2 類聲明本報(bào)告采用java編程語言,一共構(gòu)造了六個類:1、Candidate; 2、Manager; 3、UserInterface;4、MainGraph;5、VoteGraph ;6、ResultGraph。2.2.1、候選者類:Candidatepublic class Candidate private String name;/候選者姓名private int id;/候選者的編號private int num; / 得票
3、數(shù)量private 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() ;publ
4、ic void setVoteResult(double voteResult) ;public boolean isVote();public void setVote(boolean isVote) ;2.2.2、管理類:Manager類public class Manager public int candidates; / 候選人的數(shù)量public int percentage; / 當(dāng)選標(biāo)準(zhǔn)(百分比)public int voters = 0; / 投票人數(shù)量List<Candidate> listc ;/ 裝載候選者的容器public static void main(
5、String args) ;public void calculateResult() ;/ 計(jì)算結(jié)果 2.2.3、窗口的操作類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
6、 p2;/投票面板public JPanel p3;/顯示投票結(jié)果的面板public List<JTextField> list_textfield ;/裝載候選人姓名的容器public List<JRadioButton> list_jradiobutton ;/投票public UserInterface(Manager m) ;public void update() ;/窗口中增刪組建后立即更新public void addCandi(int num);/panel1輸入侯選者姓名完成后,生成候選者對象 2.2.4、輸入面板類:MainGraphpublic c
7、lass MainGraphprivate UserInterface userInterface; /與主面板的通信public MainGraph(UserInterface userInterface) ;/MainGraph的構(gòu)造函數(shù)public void launchMainGraph() ;/加載主面板2.2.5、投票面板類:VoteGraph public class VoteGraph private UserInterface userInterface;/與主面板的通信public VoteGraph(UserInterface userInterface) ;/構(gòu)造函數(shù)p
8、ublic void launchVoteGraph();/加載投票面板2.2.6、顯示結(jié)果類:ResultGraphpublic class ResultGraph private UserInterface userInterface;/與主面板的通信public ResultGraph(UserInterface userInterface) ;/構(gòu)造函數(shù)public void launchResultGraph() ;/加載顯示結(jié)果的面板3 功能實(shí)現(xiàn)3.1 窗口顯示點(diǎn)擊運(yùn)行后彈出一個窗口(Panel1),要求用戶輸入候選人的個數(shù)(1-12)以及當(dāng)選標(biāo)準(zhǔn)(若為50%,只需輸入50即可)
9、假若依次輸入12, 50.點(diǎn)擊確定后,窗口中會提示輸入侯選人的姓名,候選人的編號是從小到大依次生成的。依次輸入12人的姓名點(diǎn)擊提交后,就會彈出投票的窗口假若共有7名投票人參與投票(每次投票完點(diǎn)擊提交即為完成依次投票)投票過程如下:投票者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
10、號:劉莉莉 4號:尹聰敏 5號:張三10號:王小慧 11號:李四 12號:王龍賀投票者7:1號:吳紅巖 2號:劉莉莉 3號:邵芳 4號:尹聰敏 7號:李澤最終的投票結(jié)果如下圖所示: 3.2 功能1整個系統(tǒng)的UML時(shí)序圖如下圖所示:附錄:程序源代碼1、Candidate 的詳細(xì)代碼:public class Candidate private String name;/候選者姓名private int id;/候選者的編號private int num; / 得票數(shù)量private double voteResult; /得票率private boolean isVote;/是否中選Candid
11、ate(String name, int id) = name;this.id = id;this.num = 0;this.voteResult = 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
12、void setNum(int num) this.num = num;public double getVoteResult() return voteResult;public 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、 Ma
13、nager類的詳細(xì)代碼import java.util.ArrayList;import java.util.List;public class Manager public int candidates; / 候選人的數(shù)量public int percentage; / 當(dāng)選標(biāo)準(zhǔn)(百分比)public int voters = 0; / 投票人數(shù)量List<Candidate> listc = new ArrayList<Candidate>();public static void main(String args) Manager m = new Manager(
14、);UserInterface ui = new UserInterface(m);MainGraph mainGraph = new MainGraph(ui);mainGraph.launchMainGraph();public void calculateResult() double d;for (int i = 0; i < candidates; i+) Candidate c = listc.get(i);d = (double) c.getNum() / voters;c.setVoteResult(double) Math.round(d * 10000) / 100)
15、;if (d >= percentage * 0.01) c.setVote(true);3、 UserInterface類的詳細(xì)代碼:import java.awt.Color;import java.awt.Container;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.ut
16、il.Vector;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.SwingConstants;import javax.swing.table.Default
17、TableCellRenderer;/* * * author why * */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é)果的面板pu
18、blic List<JTextField> list_textfield = new ArrayList<JTextField>();public List<JRadioButton> list_jradiobutton = new ArrayList<JRadioButton>();public UserInterface(Manager m) super("歡迎來到投票管理系統(tǒng)");this.manager = m;this.setVisible(true);this.setBounds(150, 30, 700, 700
19、);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setResizable(false);this.setBackground(Color.black);contentPanel = this.getContentPane();public void update() this.repaint();this.setVisible(true);public void addCandi(int num) JTextField text_name;JLabel label_name;JButton submit = new JBut
20、ton("提交");String ss = ""int x1 = 80, x2 = 200, y = 150, w = 150, h = 20;int yy = y;for (int i = 1; i <= num; i+) if (y >= this.getHeight() - 250) y = yy;x1 = x1 + 300;x2 = x2 + 300;y += 50;text_name = new JTextField(); / 新建輸入姓名的文本框label_name = new JLabel(ss);label_name.setT
21、ext("候選人 " + 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.addActio
22、nListener(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ù)輸入的姓名生成一個候選者manager.listc.add(candi); / 把候選者加入到list中VoteGraph v
23、oteGraph = new VoteGraph(UserInterface.this);voteGraph.launchVoteGraph(); / 加載投票面板(Panel2);p1.add(submit);4、 MainGraph類的詳細(xì)代碼:import java.awt.Color;import java.awt.Container;import java.awt.Font;import java.awt.HeadlessException;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;i
24、mport javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;/* * 系統(tǒng)的主界面,接受候選者人數(shù),以及當(dāng)選的標(biāo)準(zhǔn) * author why * */public class MainGraphprivate UserInterface userInterface; /與主面板的通信public MainGraph(UserInterface userInterface) super();this.userInterface = userI
25、nterface;public void launchMainGraph() userInterface.p1 = new JPanel();userInterface.p1.setLayout(null);userInterface.p1.setBackground(Color.orange);userInterface.contentPanel.add(userInterface.p1);JLabel lab = new JLabel("請輸入投票信息");lab.setBounds(200, 30, 250, 50);int size = 25;lab.setFont
26、(new Font("Serif", Font.PLAIN, size);JLabel label = new JLabel("請輸入候選人的個數(shù)(1-12):");final JTextField text = new JTextField(); / 輸入候選人的個數(shù)JLabel labelp = new JLabel("請輸當(dāng)選標(biāo)準(zhǔn)(百分比):");final JTextField pertage = new JTextField(); / 輸入當(dāng)選百分比JButton b = new JButton("確定"
27、); / 對候選人個數(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 ActionListener() public void actionPerformed(ActionEvent e) userInterface.manager.ca
28、ndidates = Integer.parseInt(text.getText(); / 得到候選者的個數(shù)userInterface.addCandi(userInterface.manager.candidates);userInterface.manager.percentage = Integer.parseInt(pertage.getText(); / 得到當(dāng)選百分比);userInterface.p1.add(label);userInterface.p1.add(lab);userInterface.p1.add(text);userInterface.p1.add(b);us
29、erInterface.p1.add(labelp);userInterface.p1.add(pertage);userInterface.update();5、 VoteGraph類的詳細(xì)代碼:import java.awt.Color;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Iterator;import javax.swing.JButton;import javax.swing.JLabel;import j
30、avax.swing.JPanel;import javax.swing.JRadioButton;public class VoteGraph private UserInterface userInterface;/與主面板的通信public VoteGraph(UserInterface userInterface) super();this.userInterface = userInterface;public void launchVoteGraph() userInterface.list_jradiobutton.clear();int x = 80, y = 150, w =
31、 120, h = 20;int yy = y;JRadioButton jrb;userInterface.contentPanel.removeAll();userInterface.p2 = new JPanel();userInterface.contentPanel.add(userInterface.p2);userInterface.p2.setLayout(null);userInterface.p2.setBackground(Color.orange);JLabel label = new JLabel("請為候選者投票");label.setBound
32、s(200, 100, 250, 50);int size = 25;label.setFont(new Font("Serif", Font.PLAIN, size);JButton voter_submit = new JButton("提交");voter_submit.setBounds(100, userInterface.getHeight() - 150, 100, 20);voter_submit.addActionListener(new ActionListener() public void actionPerformed(Acti
33、onEvent e) userInterface.manager.voters+;for (int i = 0; i < userInterface.manager.candidates; i+) if (userInterface.list_jradiobutton.get(i).isSelected() userInterface.manager.listc.get(i).setNum(userInterface.manager.listc.get(i).getNum() + 1);userInterface.contentPanel.remove(userInterface.p2)
34、;launchVoteGraph();userInterface.update(););JButton result_submit = new JButton("顯示結(jié)果");result_submit.setBounds(370, userInterface.getHeight() - 150, 100, 20);result_submit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) userInterface.manager.calculateResu
35、lt();ResultGraph result = new ResultGraph(userInterface);result.launchResultGraph();userInterface.update(););Iterator<Candidate> iterator = userInterface.manager.listc.iterator();for (int i = 1; i <= userInterface.manager.candidates; i+) / 添加候選者以備投票用Candidate cand = iterator.next();if (y &g
36、t;= userInterface.getHeight() - 250) y = yy;x = x + 300;y += 50;jrb = new JRadioButton(i + "號: " + cand.getName();jrb.setBounds(x, y, w, h);userInterface.list_jradiobutton.add(jrb);userInterface.p2.add(jrb);userInterface.update();userInterface.p2.add(voter_submit);userInterface.p2.add(resu
37、lt_submit);userInterface.p2.add(label);userInterface.contentPanel.add(userInterface.p2);userInterface.update();6、 ResultGraph類的詳細(xì)代碼:import java.awt.Color;import java.awt.Font;import java.util.Vector;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing
38、.JTable;import javax.swing.table.DefaultTableCellRenderer;public class ResultGraph private UserInterface userInterface;/與主面板的通信public ResultGraph(UserInterface userInterface) super();this.userInterface = userInterface;public void launchResultGraph() JLabel label = new JLabel("最終結(jié)果");label.
39、setBounds(300, 50, 250, 50);int size = 25;label.setFont(new Font("Serif", Font.PLAIN, size);JLabel la = new JLabel("共有" + userInterface.manager.voters + "個投票人 當(dāng)選標(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(); / 支持滾動scrollPane.setBounds(100, 150, 500, 380);String columnNames = "候選者編號", "姓名", "票數(shù)&quo
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 出租鋪合同范例
- 臨時(shí)家具租賃合同標(biāo)準(zhǔn)文本
- 勞動 用工合同范本
- 貨幣政策借款合同
- 臨時(shí)店鋪合同樣本
- 包工加工合同樣本
- 甘棠中學(xué)2013年秋季學(xué)期政史組教研工作計(jì)劃
- 住宿預(yù)定服務(wù)合同樣本
- 婚禮策劃師勞動合同
- 2024年浙江臺州學(xué)院繼續(xù)教育學(xué)院編制外合同工招聘筆試真題
- 第9課 兩宋的政治和軍事 教學(xué)課件(共25張) 高中歷史統(tǒng)編版(部編版)必修 中外歷史綱要(上)
- 上海市歷年中考語文文言文閱讀試題49篇(含答案與翻譯)(截至2024年)
- 廣播節(jié)目播音主持知到智慧樹章節(jié)測試課后答案2024年秋浙江工業(yè)大學(xué)
- 化妝品生產(chǎn)防滲漏質(zhì)量控制措施
- 政務(wù)服務(wù)知識培訓(xùn)課件
- 政府績效評估 課件 蔡立輝 第6-10章 政府績效評估的結(jié)果應(yīng)用與改進(jìn) -政府績效評估在當(dāng)代中國的推進(jìn)
- 2025年職教高考對口升學(xué) 護(hù)理類 專業(yè)綜合模擬卷(3)(原卷版)(四川適用)
- 煙霧病教學(xué)查房
- 風(fēng)機(jī)及塔筒吊裝工程吊裝方案
- 交流電機(jī)控制原理及控制系統(tǒng) 習(xí)題及答案 第2-12章 交流電機(jī)調(diào)速系統(tǒng)功率電子電路- 全數(shù)字交流電機(jī)調(diào)速系統(tǒng)設(shè)計(jì)
- 【MOOC】電子線路設(shè)計(jì)、測試與實(shí)驗(yàn)(二)-華中科技大學(xué) 中國大學(xué)慕課MOOC答案
評論
0/150
提交評論