?? testcenter.java
字號:
/**
* TestCenter.java
* 本代碼為教育目的而編寫,但遵循產品代碼規范。
* 任何人任何時候都可以使用此代碼,但需說明引用的代碼來源于
* www.fangsoft.org。
* 歡迎任何建議。
* 訪問我們:
* 電子郵件:fangsoft.com@gmail.com
* 網站: www.fangsoft.org
* =====================================
* This code is for software education,but it follows production code quality.
* Anyone can use this code anywhere, but you should comment the code is from
* www.fangsoft.org.
* Any suggestion from you is appreciated.
* Visit us by
* email: fangsoft.com@gmail.com
* websiste: www.fangsoft.org
*/
package org.fangsoft.testcenter.main;
import static org.fangsoft.util.Console.output;
import org.fangsoft.testcenter.view.console.WelcomeView;
/*import static org.fangsoft.util.Console.prompt;
import static org.fangsoft.util.Console.promptYesNo;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.fangsoft.testcenter.dao.db.CustomerDBDao;
import org.fangsoft.testcenter.dao.db.QuestionDBDao;
import org.fangsoft.testcenter.dao.db.QuestionResultDBDao;
import org.fangsoft.testcenter.dao.db.TestDBDao;
import org.fangsoft.testcenter.dao.db.TestResultDBDao;
import org.fangsoft.testcenter.model.ChoiceItem;
import org.fangsoft.testcenter.model.Customer;
import org.fangsoft.testcenter.model.Question;
import org.fangsoft.testcenter.model.QuestionResult;
import org.fangsoft.testcenter.model.Test;
import org.fangsoft.testcenter.model.TestResult;
import org.fangsoft.util.Console;*/
/**
* @author fangsoft 2007-2-10
*
*/
public class Testcenter {
public static void main(String[] args) {
//run();
runOnMVC();
}
private static void runOnMVC() {
WelcomeView view=new WelcomeView();
TestController tc=new TestController();
view.addObserver(tc);
view.display();
}
/*public static void main(String[] args) {
welcome();
Customer customer = login();
if (customer == null) {
exit("用戶名或口令錯,不能登錄,系統退出");
}
boolean response = promptYesNo("確認參加考試嗎?", "是:y", "否,退出:n");
if (!response)
exit("系統退出");
Test test = selectTest();
TestResult tr = takeTest(test, customer);
reportTestResult(tr);
exit(0);
}*/
/*public static Customer login() {
output("參加考試前請先登錄,輸入完成后按enter確認:");
int count = 0;
String userId, password;
int maxLogin = 3;
Customer customer = null;
for (count = 0; count < maxLogin; count++) {
userId = prompt("輸入用戶名稱:");
password = prompt("輸入用戶密碼:");
// customer=Customer.login(userId, password);
customer = CustomerDBDao.getInstance().login(userId, password);
if (customer != null) {
break;
}
output("用戶名或密碼錯誤不能登錄,重新登錄." + "登錄" + maxLogin + "次不成功,系統將退出."
+ "這是" + (count + 1) + "次");
}
return customer;
}
public static void welcome() {
String user = System.getProperty("user.name");
output("歡迎你," + user + " 參加fangsoft考試中心的考試!");
output("今天是%1$tY年%1$tm月%1$td日%1$ta%n", Calendar.getInstance());
output("你的操作系統是:" + System.getProperty("os.name"));
}
public static TestResult takeTest(Test test, Customer customer) {
output("==========開始考試===========");
output("考試名稱:%1$5s%n" + "考試簡述:%2$5s%n" + "考試問題:%3$5s%n"
+ "考試時間:%4$5s分鐘%n", test.getName(), test.getDescription(), test
.getNumQuestion(), test.getTimeLimitMin());
long start = System.currentTimeMillis();
output("注意你有%1$s分鐘答題,現在時間是:%2$tT%n", test.getTimeLimitMin(), start);
TestResult tr = new TestResult();
tr.setCustomer(customer);
tr.setTest(test);
tr.setStatus(TestResult.Status.TESTING);
tr.setStartTime(new Timestamp(start));
QuestionDBDao.getInstance().loadQuestion(test);
for (Question q : test.getQuestion()) {
QuestionResult qr = new QuestionResult();
qr.setQuestion(q);
qr.setAnswer(null);
tr.addQuestionResult(qr);
}
tr.save();
TimeThread t = new TimeThread();
int count = 0;
tr.setStartTime(new Timestamp(start));
t.start(test, tr);
for (Question q : test.getQuestion()) {
if (t.timeTread == null) {
System.out.println("超時提交試卷!");
exit(0);
}
q.assignLabel(ChoiceItem.LABEL);
String answer = prompt(count + 1, q);
QuestionResult qr =tr.getQuestionResult(count);
qr.setQuestion(q);
qr.setAnswer(answer);
qr.computeAnswer();
tr.reworkList(qr, count);
tr.setCount(count++);
long end = System.currentTimeMillis();
tr.setEndTime(new Timestamp(end));
}
long end = tr.getEndTime().getTime();
tr.setEndTime(new Timestamp(end));
tr.commitTest();
tr.updatte();
output("考試結束,現在時間是:%1$tT%n", end);
return tr;
}
// 報告考試結果
public static void reportTestResult(TestResult tr) {
output("==========考試報告===========");
long duration = (tr.getEndTime().getTime() - tr.getStartTime()
.getTime())
/ (1000 * 60);
output("你花了%1$s分鐘考試%n", duration);
output("%1$8s%2$8s%3$8s%4$8s%n", "題號", "你的答案", "正確答案", "對錯");
int count = 0;
for (QuestionResult qr : tr.getQuestionResult()) {
output("%1$8s%2$8s%3$8s%4$8s%n", ++count, qr.getAnswer(), qr
.getQuestion().getAnswer(), qr.getResult() ? "right"
: "wrong");
}
boolean pass = tr.Pass() == 1 ? true : false;
String displayPass = "";
if (pass)
displayPass = "恭喜,你通過了考試";
else
displayPass = "很遺憾,你沒有通過考試";
output("你考試的得分是:" + tr.getScore() + "," + displayPass);
}
public static Test selectTest() {
output("fangsoft考試中心提供的所有考試:");
List<Test> allTest = TestDBDao.getInstance().findAllTest();
int count = 0;
for (Test test : allTest) {
output((++count) + ". " + test.getName() + ", 輸入:" + count);
}
while (true) {
String response = Console.prompt("請選擇考試類型:");
try {
int index = Integer.parseInt(response);
if (1 <= index && index <= allTest.size()) {
return allTest.get(index - 1);
}
} catch (Exception ex) {
}
}
} */
static void exit(Object msg) {
output(msg);
System.exit(1);// 異常退出
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -