⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console.java

📁 纯JAVA代码的考试系统
💻 JAVA
字号:
/**
 * Console.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.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;

import org.fangsoft.testcenter.model.ChoiceItem;
import org.fangsoft.testcenter.model.Question;

/**
 * @author fangsoft
 * 2007-2-10
 *
 */
public class Console {
	
	public static final String YES = "y";
	public static final String NO = "n";
	private static BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	private static PrintStream out=System.out;
	
	public static void output(Object msg){
		out.println(msg);
	}
	public static void output(String format, Object... msgs) {
		out.printf(format, msgs);
	}
	
	public static String read(){
		String result="";
		try {
			result= input.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public static String prompt(int pos,Question q){
		output("%1$s. %2$s%n",pos,q.getName());
		for(ChoiceItem item:q.getChoiceItem()){
			output("   %1$s. %2$s%n",item.getLabel(),item.getName());
		}
		output("输入答案:");
		return read();
	}
	
	public static String prompt(int pos,Object q,Object[] options){
		output(pos+".");
		return prompt(q,options);
	}
	
	public static String prompt(Object q,Object... options){
		output(q);
		if(options.length==1){
			output(options[0]);
		}else{
			for(int i=0;i<options.length;i++){
				output("%1$s. %2$s%n",i+1,options[i]);
			}
		}
		return read();
	}
	
	public static boolean promptYesNo(Object q,Object... options){
		output(q);
		if(options.length==1){
			output(options[0]);
		}else{
			for(int i=0;i<options.length;i++){
				output("%1$s. %2$s%n",i+1,options[i]);
			}
		}
		String answer=read();
		if(answer!=null && answer.equalsIgnoreCase(YES))return true;
		return false;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -