Package model

Examples of model.Context


     * @throws java.io.IOException
     * @throws java.lang.ClassNotFoundException
     */
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        QuestionList questionList = new QuestionList();
        Context context = null;
        int attempt = 0;
        int rightAnswers = 0;
        String result;

        ServerSocket server = new ServerSocket(24891);
        System.out.println("Server Started");
        Socket socket = server.accept();
        System.out.println("New client on port" + socket.getPort());
        ObjectOutputStream output = new ObjectOutputStream(socket.getOutputStream());
        ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
       
        while (true) {

            if (questionList.next() != null) {
                context = readQuestion(questionList.next());
            }
            output.writeObject(context);
            output.flush();
            context = (Context) input.readObject();

            attempt++;
            if (questionList.isRight(context.getVariant())) {
                result = "Congratulations! It is the right answer";
                rightAnswers++;
            } else {
                result = "It is the wrong answer";
            }
            result = result.concat(attempt % 10 == 0 ? (" " + rightAnswers + "/" + attempt) : "");

            context.setResult(result);
            output.writeObject(context);
            output.flush();
        }
    }
View Full Code Here


            output.flush();
        }
    }

    private static Context readQuestion(Question question) {
        Context c = new Context();
        c.setQuestion(question.getQuestion());
        c.setVariants(question.getVariants());
        return c;
    }
View Full Code Here

            System.exit(0);
        }
        ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
        ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
        while (true) {
            Context context = (Context) ois.readObject();
            System.out.println(context.getQuestion());
            for (String variant : context.getVariants()) {
                System.out.println(variant);
            }
            context.setVariant(Integer.parseInt(keyboard.readLine()));
            oos.writeObject(context);
            oos.flush();
            context = (Context) ois.readObject();
            System.out.println(context.getResult());
        }
    }
View Full Code Here

TOP

Related Classes of model.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.