當前位置:首頁 » 操作系統 » 手機投票源碼

手機投票源碼

發布時間: 2023-12-01 03:06:29

A. java做投票系統

java做投票系統,設計程序如下:

import java.util.Set; //調用java.util.Set
import java.util.HashSet;//調用java.util.HashSet
import java.util.Iterator;//調用java.util.Iterator

public class Voter { //定義類
private static final int MAX_COUNT=100; //靜態變數,最大投票數,到達此數就停止投票
private static int count; //靜態變數,投票數
private static Set<Voter>voters=new HashSet<Voter>(); //靜態變數,存放所有已經投票的選民
private String name; //實例變數,投票人姓名

public Voter(String name){this.name=name;} //定義名字字元串函數

/**投票*/
public void voteFor(){ //投票函數
if(count==MAX_COUNT){ //如果計數結果等於投票人數最大值
System.out.println("投票活動已經結束"); //列印投票活動已經結束
return; //返回主函數
}
if(voters.contains(this)) //如果已包含投票人姓名
System.out.println(name+":你不允許重復投票!"); //列印投票人姓名和你不允許重復投票!
else{ //否則
count++; //計數加一
voters.add(this); //調用字元串函數添加投票人姓名
System.out.println(name+":感謝你投票!"); //列印投票人姓名和感謝你投票!
}
}

/**列印投票結果*/
public static void printVoteResult(){ //投票結果函數
System.out.println("當前投票數為:"+count); //列印當前投票數為,並且統計人數
System.out.println("參與投票的選民名單如下"); //列印參與投票的選民名單如下
for(Voter voter:voters){ //遍歷voters集合
System.out.println(voter.name); //列印輸出投票名稱
}
}

public static void main(String args[]) { //主函數
Voter tom=new Voter("Tom"); //開辟空間定義元素tom
Voter mike=new Voter("Mike"); //開辟空間定義元素mike
Voter jack=new Voter("Jack"); //開辟空間定義元素jack

tom.voteFor(); //進入tom的投票函數
tom.voteFor(); //進入tom的投票函數
mike.voteFor(); //進入mike的投票函數
jack.voteFor(); //進入jack的投票函數

Voter.printVoteResult(); //投票結果列印函數

}

}

B. 投票統計器(c++源代碼)

如果你文本文件內的名字中間用空格隔開就好了,很容易實現統計的

這是加了空格後的統計

這樣的效果可以嗎

C. 跪求html簡潔投票系統源碼,我已經在網上找了6天了,腦殼青痛!

六天,看來你夠苦的.幫你一下,用application做的,不知你是否滿意,
首先在你網站根目錄下新建一個名為:Global.asa的文件,然後把下列代碼貼上去:
<script language="vbscript" runat="server">
Sub Application_OnStart
application("yes")=0
application("no")=0
End Sub
</script>

然後再建一個投票的ASP文件,內容:
<style type="text/css">
<!--
.Vote {
height: 15px;
width: 200px;
border: 1px solid #0033FF;
}
#cYes {
background-color: #FF6600;
height: 15px;
width: 100px;
}
#cNo {
background-color: #FF6600;
height: 15px;
width: 100px;
}
-->
</style>
<form action="" method="post">
做一個投票系統難嗎?<br />
<input name="yes" type="radio" value="yes" onclick="if (this.checked==true) no.checked=false;" />贊成<br />
<input name="no" type="radio" value="no" onclick="if (this.checked==true) yes.checked=false;"/>反對<br />
<input name="投票" type="submit" value="投票" />
</form>
<%
nyes=0
nNo=0
'如果想重新計票,用下面四行
'application.lock()
'application("yes")=application("yes")+1
'application("no")=application("no")+1
'application.unlock()

count=application("yes")+application("no")
if count<>0 then
nyes=int(application("yes")*200/count)
nNo=int(application("no")*200/count)
end if

sYes=Request.form("yes")
sNo=Request.form("no")
act= Request.form("投票")
if act="投票" Then
if sYes="yes" Then
application.lock()
application("yes")=application("yes")+1
application.unlock()
Else
if sNo="no" then
application.lock()
application("no")=application("no")+1
application.unlock()
end if
End if
'圖形化顯示投票結果
count=application("yes")+application("no")
if count<>0 then
nyes=int(application("yes")*200/count)
nNo=int(application("no")*200/count)
end if
end if
%>

贊成:<%=application("yes")%>票
<div class="Vote" ><div ID="cYes" neme="cYes" style="width:<%=nyes%>px;"></div></div>
反對::<%=application("no")%>票
<div class="Vote" ><div ID="cNo" neme="cNo" style="width:<%=nNo%>px;"></div></div>

D. jsp投票系統求源代碼!可以連資料庫的!

<p style=line-height: 150%><SPAN style="FONT-SIZE: 12px"><STRONG>這是用文本文件作為存儲載體的投票系統:</STRONG></SPAN>
<p style=line-height: 150%><SPAN style="FONT-SIZE: 12px"><STRONG>vote.java:</STRONG></SPAN>
<SPAN style="FONT-SIZE: 12px"><STRONG></STRONG> <p style=line-height: 150%>
// Java Document
package vote;
import java.io.*;
import java.util.*;
public class vote extends Object
{
public String filePath="";
public int n;
private File voteFile;
private BufferedReader fileRead;
private PrintWriter fileWrite;
public String systemMessage="";
private String voteStr[]=new String[10];
public int voteNum[]=new int[10];
public void createFile()
throws FileNotFoundException
{
voteFile=new File(filePath);
if(!voteFile.exists())
{
fileWrite=new PrintWriter(new FileOutputStream(filePath));
for(int i=0;i<n;i++) fileWrite.println("0");
fileWrite.close();
}
}
public void writeFile()
throws FileNotFoundException
{
fileWrite=new PrintWriter(new FileOutputStream(filePath));
for(int i=0;i<n;i++)
{
fileWrite.println(voteNum[i]);
}
fileWrite.close();
}
public void readFile()
throws FileNotFoundException
{
fileRead=new BufferedReader(new FileReader(filePath));
for(int i=0;i<n;i++)
{
try
{voteStr[i]=fileRead.readLine();
}
catch(IOException f)
{
voteStr[i]="0";}
voteNum[i]=Integer.parseInt(voteStr[i]);
}
try
{
fileRead.close();
}
catch(IOException d)
{
systemMessage=d.toString();
}
}
}
<p style=line-height: 150%><SPAN style="LINE-HEIGHT: 15pt"><SPAN style="FONT-SIZE: 12px"><STRONG>vote.jsp:</STRONG>

<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ page import="java.util.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.io.*"%>
<jsp:useBean id="vote" scope="request" class="vote.vote"/>
<%
String vote1=request.getParameter("lang");
vote.n=4;
vote.filePath="vote.txt";
vote.createFile();
vote.readFile();
if(vote1.compareTo("0")==0)
vote.voteNum[0]++;
if(vote1.compareTo("1")==0)
vote.voteNum[1]++;
if(vote1.compareTo("2")==0)
vote.voteNum[2]++;
if(vote1.compareTo("3")==0)
vote.voteNum[3]++;
vote.writeFile();
%>
<script language="javascript">
alert("感謝你投了寶貴的一票");
self.location="index.jsp";
</script></SPAN></SPAN>
<p style=line-height: 150%><STRONG> </STRONG><SPAN style="LINE-HEIGHT: 15pt"><SPAN style="FONT-SIZE: 12px"><STRONG>see.jsp:</STRONG>

<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ page import="java.util.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.io.*"%>
<jsp:useBean id="vote" scope="request" class="vote.vote"/>
<%
String vote1=request.getParameter("lang");
vote.n=4;
vote.filePath="vote.txt";
vote.createFile();
vote.readFile();
int total=0;
float voteFlo[]=new float[5];
for(int i=0;i<4;i++) total+=vote.voteNum[i];
for(int i=0;i<4;i++) voteFlo[i]=150*((float)vote.voteNum[i]/(float)total);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>查看調查</title>
<link href="t1.css" rel="stylesheet" type="text/css">
</head>
<body>

<table width="30%" border="0" class="t1">
<tr>
<td colspan="2"><div align="center">調查結果</div></td>
</tr>
<tr>
<td width="18%">JSP</td>
<td width="82%"><img src="bar.gif" width=<%=voteFlo[0]%> height=8> <%=vote.voteNum[0]%></td>
</tr>
<tr>
<td>ASP</td>
<td><img src="bar.gif" width=<%=voteFlo[1]%> height=8> <%=vote.voteNum[1]%></td>
</tr>
<tr>
<td>PHP</td>
<td><img src="bar.gif" width=<%=voteFlo[2]%> height=8> <%=vote.voteNum[2]%></td>
</tr>
<tr>
<td>其他</td>
<td><img src="bar.gif" width=<%=voteFlo[3]%> height=8> <%=vote.voteNum[3]%></td>
</tr>
<tr>
<td colspan="2"><div align="center"><a href="javascript:window.close();">關閉窗口</a></div></td>
</tr>
</table>
</body>
</html>
</SPAN></SPAN>
<p style=line-height: 150%><SPAN style="LINE-HEIGHT: 15pt"><SPAN style="FONT-SIZE: 12px"><SPAN style="LINE-HEIGHT: 15pt"><SPAN style="FONT-SIZE: 12px"><STRONG>index.jsp:</STRONG>
</SPAN></SPAN>
</SPAN></SPAN> <p style=line-height: 150%><SPAN style="LINE-HEIGHT: 15pt"><SPAN style="FONT-SIZE: 12px"><%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>投票</title>
<link href="t1.css" rel="stylesheet" type="text/css">
</head>
<script language="javascript">
function cw()
{window.open("see.jsp","mywindow","toolbar=no,left=150,top=200,width=270,height=350,menubar=no,systemMenu=no");
}
</script>
<body>
<table width="15%" height="250" align="left">
<tr>
<td><form name="form1" method="post" action="vote.jsp">
<table width="100%" height="250" border="1" align="center" bordercolor="#9966CC" class="t1">
<tr>
<td><div align="left">你所使用的開發語言</div></td>
</tr>
<tr>
<td><input type="radio" name="lang" value="0">
JSP</td>
</tr>
<tr>
<td><input type="radio" name="lang" value="1">
ASP</td>
</tr>
<tr>
<td><input type="radio" name="lang" value="2">
PHP</td>
</tr>
<tr>
<td><input type="radio" name="lang" value="3">
其他 </td>
</tr>
<tr>
<td><div align="center">
<input name="vote" type="image" src="poll.gif" width="40" height="20" border="0">
<a href="javascript:cw()"><img src="see.gif" width="40" height="20" border="0"></a></div></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
</SPAN></SPAN></SPAN>

E. 網站投票系統源代碼(java web)

http://www.onegreen.net/code/HTML/10633.html 你看看這個行不行 如果行的話 請採納

熱點內容
數據模型於資料庫系統 發布:2024-07-27 09:59:56 瀏覽:849
網站ip訪問量 發布:2024-07-27 09:59:55 瀏覽:286
java字元串字元數組 發布:2024-07-27 09:59:13 瀏覽:593
如何利用無線網路搭建伺服器 發布:2024-07-27 09:59:05 瀏覽:721
it天空解壓密碼 發布:2024-07-27 09:50:39 瀏覽:549
軟體腳本買賣 發布:2024-07-27 09:50:38 瀏覽:917
android對象轉json 發布:2024-07-27 09:50:15 瀏覽:183
安卓平板有什麼可以畫對稱的 發布:2024-07-27 09:36:03 瀏覽:133
羊創意腳本 發布:2024-07-27 09:29:30 瀏覽:895
榮耀v20升級存儲 發布:2024-07-27 09:20:19 瀏覽:486