包含JAVA簡(jiǎn)易考試系統(tǒng)代碼的詞條

java字符串考試報(bào)名系統(tǒng)

創(chuàng)建一個(gè)類(lèi),在該類(lèi)的主方法中創(chuàng)建Scanner掃描起來(lái)封裝System類(lèi)的in輸入流,然后提示用戶輸入數(shù)字,并輸入數(shù)字的位數(shù)。代碼如下: import java.util.Scanner; public class InputCode { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);// 創(chuàng)建輸入流掃描器 System.out.println("請(qǐng)輸入數(shù)字:");// 提示用戶輸入 String line = scanner.nextLine();// 獲取用戶輸入的一行文本 // 打印對(duì)輸入文本的描述 System.out.println("原來(lái)是" + line.length() + "位數(shù)字的啊"); } }

創(chuàng)新互聯(lián)公司公司2013年成立,是專(zhuān)業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站制作、成都做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元肥西做網(wǎng)站,已為上家服務(wù),為肥西各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:028-86922220

學(xué)生考試管理系統(tǒng),JAva源代碼

//主類(lèi)EnglishTest——

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class EnglishTest extends JFrame

{

TestArea testPanel=null;

Container con=null;

public EnglishTest()

{

super("模擬考試");

testPanel=new TestArea();

con=getContentPane();

con.add(testPanel,BorderLayout.CENTER);

addWindowListener(new WindowAdapter()

{ public void windowClosing(WindowEvent e)

{ System.exit(0);

}

});

setVisible(true);

setBounds(60,40,660,460);

con.validate();

validate();

}

public static void main(String args[])

{

new EnglishTest();

}

}

//讀取試題 ReadTestquestion

import java.io.*;

import java.util.*;

public class ReadTestquestion

{ String filename="",

correctAnswer="",

testContent="" ,

selection="" ;

int score=0;

long time=0;

boolean 完成考試=false;

File f=null;

FileReader in=null;

BufferedReader 讀取=null;

public void setFilename(String name)

{ filename=name;

score=0;

selection="";

try {

if(in!=null讀取!=null)

{

in.close();

讀取.close();

}

f=new File(filename);

in=new FileReader(f);

讀取=new BufferedReader(in);

correctAnswer=(讀取.readLine()).trim();

String temp=(讀取.readLine()).trim() ;

StringTokenizer token=new StringTokenizer(temp,":");

int hour=Integer.parseInt(token.nextToken()) ;

int minute=Integer.parseInt(token.nextToken());

int second=Integer.parseInt(token.nextToken());

time=1000*(second+minute*60+hour*60*60);

}

catch(Exception e)

{

testContent="沒(méi)有選擇試題";

}

}

public String getFilename()

{

return filename;

}

public long getTime()

{

return time;

}

public void set完成考試(boolean b)

{

完成考試=b;

}

public boolean get完成考試()

{

return 完成考試;

}

public String getTestContent()

{ try {

String s=null;

StringBuffer temp=new StringBuffer();

if(讀取!=null)

{

while((s=讀取.readLine())!=null)

{

if(s.startsWith("**"))

break;

temp.append("\n"+s);

if(s.startsWith("endend"))

{

in.close();

讀取.close();

完成考試=true;

}

}

testContent=new String(temp);

}

else

{

testContent=new String("沒(méi)有選擇試題");

}

}

catch(Exception e)

{

testContent="試題內(nèi)容為空,考試結(jié)束??!";

}

return testContent;

}

public void setSelection(String s)

{

selection=selection+s;

}

public int getScore()

{ score=0;

int length1=selection.length();

int length2=correctAnswer.length();

int min=Math.min(length1,length2);

for(int i=0;imin;i++)

{ try{

if(selection.charAt(i)==correctAnswer.charAt(i))

score++;

}

catch(StringIndexOutOfBoundsException e)

{

i=0;

}

}

return score;

}20:10 03-8-31

public String getMessages()

{

int length1=selection.length();

int length2=correctAnswer.length();

int length=Math.min(length1,length2);

String message="正確答案:"+correctAnswer.substring(0,length)+"\n"+

"你的回答:"+selection+"\n";

return message;

}

}

//考試區(qū)域TestArea

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.io.*;

class FileName implements FilenameFilter

{

String str=null;

FileName (String s)

{

str="."+s;

}

public boolean accept(File dir,String name)

{

return name.endsWith(str);

}

}

public class TestArea extends JPanel implements ActionListener,ItemListener,Runnable

{

Choice list=null;

JTextArea 試題顯示區(qū)=null,消息區(qū)=null;

JCheckBox box[];

JButton 提交該題答案,讀取下一題,查看分?jǐn)?shù);

ReadTestquestion 讀取試題=null;

JLabel welcomeLabel=null;

Thread countTime=null;

long time=0;

JTextField timeShow=null;

boolean 是否關(guān)閉計(jì)時(shí)器=false,

是否暫停計(jì)時(shí)=false;

JButton 暫停或繼續(xù)計(jì)時(shí)=null;

public TestArea()

{

list= new Choice();

String 當(dāng)前目錄=System.getProperty("user.dir");

File dir=new File(當(dāng)前目錄);

FileName fileTxt=new FileName("txt");

String fileName[]=dir.list(fileTxt);

for(int i=0;ifileName.length;i++)

{

list.add(fileName[i]);

}

試題顯示區(qū)=new JTextArea(15,12);

試題顯示區(qū).setLineWrap(true);

試題顯示區(qū).setWrapStyleWord(true);

試題顯示區(qū).setFont(new Font("TimesRoman",Font.PLAIN,14));

試題顯示區(qū).setForeground(Color.blue);

消息區(qū)=new JTextArea(8,8);

消息區(qū).setForeground(Color.blue);

消息區(qū).setLineWrap(true);

消息區(qū).setWrapStyleWord(true);

countTime=new Thread(this);

String s[]={"A","B","C","D"};

box=new JCheckBox[4];

for(int i=0;i4;i++)

{

box[i]=new JCheckBox(s[i]);

}

暫?;蚶^續(xù)計(jì)時(shí)=new JButton("暫停計(jì)時(shí)");

暫停或繼續(xù)計(jì)時(shí).addActionListener(this);

提交該題答案=new JButton("提交該題答案");

讀取下一題=new JButton("讀取第一題");

讀取下一題.setForeground(Color.blue);

提交該題答案.setForeground(Color.blue);

查看分?jǐn)?shù)=new JButton("查看分?jǐn)?shù)");

查看分?jǐn)?shù).setForeground(Color.blue);

提交該題答案.setEnabled(false);

提交該題答案.addActionListener(this);

讀取下一題.addActionListener(this);

查看分?jǐn)?shù).addActionListener(this);

list.addItemListener(this);

讀取試題=new ReadTestquestion();

JPanel pAddbox=new JPanel();

for(int i=0;i4;i++)

{

pAddbox.add(box[i]);

}

Box boxH1=Box.createVerticalBox(),

boxH2=Box.createVerticalBox(),

baseBox=Box.createHorizontalBox();

boxH1.add(new JLabel("選擇試題文件"));

boxH1.add(list);

boxH1.add(new JScrollPane(消息區(qū)));

boxH1.add(查看分?jǐn)?shù));

timeShow=new JTextField(20);

timeShow.setHorizontalAlignment(SwingConstants.RIGHT);

timeShow.setEditable(false);

JPanel p1=new JPanel();

p1.add(new JLabel("剩余時(shí)間:"));

p1.add(timeShow);

p1.add(暫?;蚶^續(xù)計(jì)時(shí));

boxH1.add(p1);

boxH2.add(new JLabel("試題內(nèi)容:"));

boxH2.add(new JScrollPane(試題顯示區(qū)));

JPanel p2=new JPanel();

p2.add(pAddbox);

p2.add(提交該題答案);

p2.add(讀取下一題);

boxH2.add(p2);

baseBox.add(boxH1);

baseBox.add(boxH2);

setLayout(new BorderLayout());

add(baseBox,BorderLayout.CENTER);

welcomeLabel=new JLabel("歡迎考試,提高英語(yǔ)水平",JLabel.CENTER);

welcomeLabel.setFont(new Font("隸書(shū)",Font.PLAIN,24));

welcomeLabel.setForeground(Color.blue);

add(welcomeLabel,BorderLayout.NORTH);

}

public void itemStateChanged(ItemEvent e)

{

timeShow.setText(null);

是否關(guān)閉計(jì)時(shí)器=false;

是否暫停計(jì)時(shí)=false;

暫停或繼續(xù)計(jì)時(shí).setText("暫停計(jì)時(shí)");

String name=(String)list.getSelectedItem();

讀取試題.setFilename(name);

讀取試題.set完成考試(false);

time=讀取試題.getTime();

if(countTime.isAlive())

{

是否關(guān)閉計(jì)時(shí)器=true;

countTime.interrupt();

}

countTime=new Thread(this);

消息區(qū).setText(null);

試題顯示區(qū).setText(null);

讀取下一題.setText("讀取第一題");

提交該題答案.setEnabled(false);

讀取下一題.setEnabled(true);

welcomeLabel.setText("歡迎考試,你選擇的試題:"+讀取試題.getFilename());

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==讀取下一題)

{

讀取下一題.setText("讀取下一題");

提交該題答案.setEnabled(true);

String contentTest=讀取試題.getTestContent();

試題顯示區(qū).setText(contentTest);

消息區(qū).setText(null);

讀取下一題.setEnabled(false);

try {

countTime.start();

}

catch(Exception event)

{

}

}

if(e.getSource()==提交該題答案)

{

讀取下一題.setEnabled(true);

提交該題答案.setEnabled(false);

String answer="?";

for(int i=0;i4;i++)

{

if(box[i].isSelected())

{

answer=box[i].getText();

box[i].setSelected(false);

break;

}

}

讀取試題.setSelection(answer);

}

if(e.getSource()==查看分?jǐn)?shù))

{

int score=讀取試題.getScore();

String messages=讀取試題.getMessages();

消息區(qū).setText("分?jǐn)?shù):"+score+"\n"+messages);

}

if(e.getSource()==暫?;蚶^續(xù)計(jì)時(shí))

{

if(是否暫停計(jì)時(shí)==false)

{

暫?;蚶^續(xù)計(jì)時(shí).setText("繼續(xù)計(jì)時(shí)");

是否暫停計(jì)時(shí)=true;

}

else if(是否暫停計(jì)時(shí)==true)

{

暫停或繼續(xù)計(jì)時(shí).setText("暫停計(jì)時(shí)");

是否暫停計(jì)時(shí)=false;

countTime.interrupt();

}

}

}

public synchronized void run()

{

while(true)

{

if(time=0)

{

是否關(guān)閉計(jì)時(shí)器=true;

countTime.interrupt();

提交該題答案.setEnabled(false);

讀取下一題.setEnabled(false);

timeShow.setText("用時(shí)盡,考試結(jié)束");

}

else if(讀取試題.get完成考試())

{

是否關(guān)閉計(jì)時(shí)器=true;

timeShow.setText("考試效果:分?jǐn)?shù)*剩余時(shí)間(秒)="+1.0*讀取試題.getScore()*(time/1000));

countTime.interrupt();

提交該題答案.setEnabled(false);

讀取下一題.setEnabled(false);

}

else if(time=1)

{

time=time-1000;

long leftTime=time/1000;

long leftHour=leftTime/3600;

long leftMinute=(leftTime-leftHour*3600)/60;

long leftSecond=leftTime%60;

timeShow.setText(""+leftHour+"小時(shí)"+leftMinute+"分"+leftSecond+"秒");

}

try

{

Thread.sleep(1000);

}

catch(InterruptedException ee)

{

if(是否關(guān)閉計(jì)時(shí)器==true)

return ;

}

while(是否暫停計(jì)時(shí)==true)

{

try

{

wait();

}

catch(InterruptedException ee)

{

if(是否暫停計(jì)時(shí)==false)

{

notifyAll();

}

}

}

}

}

}

給段最簡(jiǎn)單的java代碼 讓我新手看一下

最簡(jiǎn)單的java代碼肯定就是這個(gè)了,如下:

public class MyFirstApp

{

public static void main(String[] args)

{

System.out.print("Hello world");

}

}

“hello world”就是應(yīng)該是所有學(xué)java的新手看的第一個(gè)代碼了。如果是零基礎(chǔ)的新手朋友們可以來(lái)我們的java實(shí)驗(yàn)班試聽(tīng),有免費(fèi)的試聽(tīng)課程幫助學(xué)習(xí)java必備基礎(chǔ)知識(shí),有助教老師為零基礎(chǔ)的人提供個(gè)人學(xué)習(xí)方案,學(xué)習(xí)完成后有考評(píng)團(tuán)進(jìn)行專(zhuān)業(yè)測(cè)試,幫助測(cè)評(píng)學(xué)員是否適合繼續(xù)學(xué)習(xí)java,15天內(nèi)免費(fèi)幫助來(lái)報(bào)名體驗(yàn)實(shí)驗(yàn)班的新手快速入門(mén)java,更好的學(xué)習(xí)java!

求在線考試系統(tǒng)源代碼,做好的更好,用java語(yǔ)言寫(xiě)的,連接mysql數(shù)據(jù)庫(kù)的,在線等,急??!謝謝

1.Java連接MySQL數(shù)據(jù)庫(kù)

Java連接MySql需要下載JDBC驅(qū)動(dòng)MySQL-connector-java-5.0.5.zip(舉例,現(xiàn)有新版本)。然后將其解壓縮到任一目錄。我是解壓到D盤(pán),然后將其目錄下的MySQL-connector-java-5.0.5-bin.jar加到classpath里,具體如下:

“我的電腦”- “屬性” - “高級(jí)” - “環(huán)境變量”,在系統(tǒng)變量那里編輯classpath,將D:\MySQL-connector-java-5.0.5\MySQL-connector-java-5.0.5-bin.jar加到最后,在加這個(gè)字符串前要加“;”,以與前一個(gè)classpath區(qū)分開(kāi)。然后確定。

package hqs;

import java.sql.*;

public class DataBasePractice {

public static void main(String[] args) {

//聲明Connection對(duì)象

Connection con;

//驅(qū)動(dòng)程序名

String driver = "com.mysql.jdbc.Driver";

//URL指向要訪問(wèn)的數(shù)據(jù)庫(kù)名mydata

String url = "jdbc:mysql://localhost:3306/mydata";

//MySQL配置時(shí)的用戶名

String user = "root";

//MySQL配置時(shí)的密碼

String password = "root";

//遍歷查詢結(jié)果集

try {

//加載驅(qū)動(dòng)程序

Class.forName(driver);

//1.getConnection()方法,連接MySQL數(shù)據(jù)庫(kù)??!

con = DriverManager.getConnection(url,user,password);

if(!con.isClosed())

System.out.println("Succeeded connecting to the Database!");

//2.創(chuàng)建statement類(lèi)對(duì)象,用來(lái)執(zhí)行SQL語(yǔ)句?。?/p>

Statement statement = con.createStatement();

//要執(zhí)行的SQL語(yǔ)句

String sql = "select * from student";

//3.ResultSet類(lèi),用來(lái)存放獲取的結(jié)果集!!

ResultSet rs = statement.executeQuery(sql);

System.out.println("-----------------");

System.out.println("執(zhí)行結(jié)果如下所示:");

System.out.println("-----------------");

System.out.println(" 學(xué)號(hào)" + "\t" + " 姓名");

System.out.println("-----------------");

String name = null;

String id = null;

while(rs.next()){

//獲取stuname這列數(shù)據(jù)

name = rs.getString("stuname");

//獲取stuid這列數(shù)據(jù)

id = rs.getString("stuid");

//首先使用ISO-8859-1字符集將name解碼為字節(jié)序列并將結(jié)果存儲(chǔ)新的字節(jié)數(shù)組中。

//然后使用GB2312字符集解碼指定的字節(jié)數(shù)組。

name = new String(name.getBytes("ISO-8859-1"),"gb2312");

//輸出結(jié)果

System.out.println(id + "\t" + name);

}

rs.close();

con.close();

} catch(ClassNotFoundException e) {

//數(shù)據(jù)庫(kù)驅(qū)動(dòng)類(lèi)異常處理

System.out.println("Sorry,can`t find the Driver!");

e.printStackTrace();

} catch(SQLException e) {

//數(shù)據(jù)庫(kù)連接失敗異常處理

e.printStackTrace();

}catch (Exception e) {

// TODO: handle exception

e.printStackTrace();

}finally{

System.out.println("數(shù)據(jù)庫(kù)數(shù)據(jù)成功獲?。?!");

}

}

}

2.添加、修改、刪除操作

在上面while代碼段后面添加以下代碼段:String name = null;

String id = null;

while(rs.next()){

//獲取stuname這列數(shù)據(jù)

name = rs.getString("stuname");

//獲取stuid這列數(shù)據(jù)

id = rs.getString("stuid");

//首先使用ISO-8859-1字符集將name解碼為字節(jié)序列并將結(jié)果存儲(chǔ)新的字節(jié)數(shù)組中。

//然后使用GB2312字符集解碼指定的字節(jié)數(shù)組。

name = new String(name.getBytes("ISO-8859-1"),"gb2312");

//輸出結(jié)果

System.out.println(id + "\t" + name);

}

PreparedStatement psql;

ResultSet res;

//預(yù)處理添加數(shù)據(jù),其中有兩個(gè)參數(shù)--“?”

psql = con.prepareStatement("insert into student values(?,?)");

psql.setInt(1, 8); //設(shè)置參數(shù)1,創(chuàng)建id為5的數(shù)據(jù)

psql.setString(2, "xiaogang"); //設(shè)置參數(shù)2,name 為小明

psql.executeUpdate(); //執(zhí)行更新

//預(yù)處理更新(修改)數(shù)據(jù)

psql = con.prepareStatement("update student set stuname = ? where stuid = ?");

psql.setString(1,"xiaowang"); //設(shè)置參數(shù)1,將name改為王五

psql.setInt(2,10); //設(shè)置參數(shù)2,將id為2的數(shù)據(jù)做修改

psql.executeUpdate();

//預(yù)處理刪除數(shù)據(jù)

psql = con.prepareStatement("delete from student where stuid = ?");

psql.setInt(1, 5);

psql.executeUpdate();

//查詢修改數(shù)據(jù)后student表中的數(shù)據(jù)

psql = con.prepareStatement("select*from student");

res = psql.executeQuery(); //執(zhí)行預(yù)處理sql語(yǔ)句

System.out.println("執(zhí)行增加、修改、刪除后的數(shù)據(jù)");

while(res.next()){

name = res.getString("stuname");

id = res.getString("stuid");

name = new String(name.getBytes("ISO-8859-1"),"gb2312");

System.out.println(id + "\t" + name);

}

res.close();

psql.close();

該代碼段使用到了預(yù)處理語(yǔ)句:con.prepareStatement(String sql);

這樣生成數(shù)據(jù)庫(kù)底層的內(nèi)部命令,并將該命令封裝在preparedStatement對(duì)象中,可以減輕數(shù)據(jù)庫(kù)負(fù)擔(dān),提高訪問(wèn)數(shù)據(jù)庫(kù)速度。 運(yùn)行結(jié)果:

本文題目:包含JAVA簡(jiǎn)易考試系統(tǒng)代碼的詞條
新聞來(lái)源:http://muchs.cn/article20/doeoojo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、Google、網(wǎng)頁(yè)設(shè)計(jì)公司、響應(yīng)式網(wǎng)站、網(wǎng)站排名、網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)