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

📄 question.java

📁 自己写的轮询提问的小程序 新手刚学 多多指教 合乎哈
💻 JAVA
字号:
/*This is the Question class, according to the client. It is a crippled version of the server's QuestionCopyright (C) 2005-2006  Igor Partola, Michael J. Krikonis, Clark UniversityThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.*/package PollClient;import java.net.*;import java.io.*; public class Question {    private String QuestionName;    private String Question;    private String AnswerA;    private String AnswerB;    private String AnswerC;    private String AnswerD;    private String AnswerE;    private String AnswerF;    private int Timeout;    private int NumOfAnswers = 6;        public Question(String qn, String q, String a, String b, String c, String d, String e, String f, int t, int n) {        QuestionName = qn;        Question = q;                AnswerA = a;        AnswerB = b;        AnswerC = c;        AnswerD = d;        AnswerE = e;        AnswerF = f;                Timeout = t;        NumOfAnswers = n;    }        public Question(byte[] bytes) {        /*         * question name size = 0..3         * question size = 4..7         * answer A size = 8..11         * answer B size = 12..15         * answer C size = 16..19         * answer D size = 20..23         * answer E size = 24..27         * answer F size = 28..31         * timeout = 32..35         * number of answers = 36..39         * data = 40....         */                int qns = bytesToInt(bytes, 0);        int qs = bytesToInt(bytes, 4);        int as = bytesToInt(bytes, 8);        int bs = bytesToInt(bytes, 12);        int cs = bytesToInt(bytes, 16);        int ds = bytesToInt(bytes, 20);        int es = bytesToInt(bytes, 24);        int fs = bytesToInt(bytes, 28);        int t = bytesToInt(bytes, 32);        int n = bytesToInt(bytes, 36);        String qn = new String(bytes, 40, qns);        String q = new String(bytes, 40 + qns, qs);        String a = new String(bytes, 40 + qns + qs, as);        String b = new String(bytes, 40 + qns + qs + as, bs);        String c = new String(bytes, 40 + qns + qs + as + bs, cs);        String d = new String(bytes, 40 + qns + qs + as + bs + cs, ds);        String e = new String(bytes, 40 + qns + qs + as + bs + cs + ds, es);        String f = new String(bytes, 40 + qns + qs + as + bs + cs + ds + es, fs);                        QuestionName = qn;        Question = q;                AnswerA = a;        AnswerB = b;        AnswerC = c;        AnswerD = d;        AnswerE = e;        AnswerF = f;        Timeout = t;        NumOfAnswers = n;            }        public String getQuestionName() {        return QuestionName;    }    public String getQuestion() {        return Question;    }    public String getAnswerA() {        return AnswerA;    }    public String getAnswerB() {        return AnswerB;    }    public String getAnswerC() {        return AnswerC;    }    public String getAnswerD() {        return AnswerD;    }        public String getAnswerE() {        return AnswerE;    }    public String getAnswerF() {        return AnswerF;    }    public int getTimeout() {        return Timeout;    }     public int getNumOfAnswers() {        return NumOfAnswers;    }        public String toString() {        String s;                s = QuestionName + "\n\n" + Question  + "\n\n" + AnswerA + "      " + AnswerC +  '\n' + AnswerB + "      " + AnswerD + '\n';                return s;    }    private static int bytesToInt(byte[] b, int offset) {        int value = 0;        for (int i = 0; i < 4; i++) {            int shift = (4 - 1 - i) * 8;            value += (b[i + offset] & 0x000000FF) << shift;        }        return value;    }}

⌨️ 快捷键说明

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