diff options
author | Camil Staps | 2015-03-05 16:48:34 +0100 |
---|---|---|
committer | Camil Staps | 2015-03-05 16:48:34 +0100 |
commit | cefdb190155230e388c2135bec59d5ab52ff5a16 (patch) | |
tree | 25eadf04e9c44f199201ce8b35f48b4096f88acd /Week5/src/week5/Week5.java | |
parent | Framework week5 (diff) |
Finished week 5
Diffstat (limited to 'Week5/src/week5/Week5.java')
-rw-r--r-- | Week5/src/week5/Week5.java | 100 |
1 files changed, 92 insertions, 8 deletions
diff --git a/Week5/src/week5/Week5.java b/Week5/src/week5/Week5.java index 15323a8..992842a 100644 --- a/Week5/src/week5/Week5.java +++ b/Week5/src/week5/Week5.java @@ -1,21 +1,105 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package week5; +import java.util.LinkedList; +import java.util.List; +import java.util.Scanner; + /** - * - * @author camilstaps + * Uitwerking voor week 5 + * + * @author Thijs Heijligenberg, s4451414 + * @author Camil Staps, s4498062 */ public class Week5 { + + private final List<Question> questions = new LinkedList<Question>(); + private final List<Question> questions_2 = new LinkedList<Question>(); + + private int score_round1 = 0; + private int score_round2 = 0; /** * @param args the command line arguments */ public static void main(String[] args) { - // TODO code application logic here + Week5 w5 = new Week5(); + w5.play(); + } + + public Week5() { + questions.add(new OpenQuestion("Wat is de complexiteit van binair zoeken?", "O(log N)")); + questions.add(new OpenQuestion("Hoe lees je in Java een integer i uit een scanner s?", "i = s.nextInt();", 2)); + questions.add(new OpenQuestion("Is er verschil tussen een interface en een abstracte klasse?", "Ja", 5)); + questions.add(new OpenQuestion("Hoeveel constructoren je minstens maken bij een klasse in Java?", "0", 2)); + questions.add(new OpenQuestion("Is er een maximum aantal constructoren van een klasse in Java?", "Nee")); + + questions.add(new MCQuestion("Wat is de complexiteit van slim in situ sorteren?", new String [] { + "O(N^2)", + "O(N log N)", + "O(N)", + "O(log N)"}, 1, 4)); + questions.add(new MCQuestion("Hoe print je \"Hello world\" op een regel in Java?", new String [] { + "System.out.print(\"Hello world\");", + "System.out.println(\"Hello world\");", + "cout << \"Hello world\";"}, 1)); + questions.add(new MCQuestion("Hoe lees je in Java een niet leeg woord uit scanner s?", new String []{ + "s.nextline()", + "s.next(\"\\S+\")", + "s.next(\"\\a*\")", + "s.next(\"\\S*\")", + "s.next(\"\\\\s+\")", + "s.next(\"\\s+\")", + "s.nextString(\"\\s*\")", + "s.next(\"\\\\S+\")", + "s.nextString()"}, 7, 1)); + + questions.add(new TCQuestion("Deze opgave is eigenlijk niet zo moeilijk.", "Juist", "Onjuist", 0, 5)); + + } + + private void play() { + round1(); + System.out.println(); + round2(); + System.out.println(); + + System.out.println("Score ronde 1: " + score_round1); + System.out.println("Score ronde 2: " + score_round2); + } + + private void round1() { + Scanner sc = new Scanner(System.in); + + for (Question q : questions) { + System.out.println(q); + if (q.isCorrect(sc.nextLine())) { + System.out.println("Goed zo!\n"); + score_round1 += q.getWeight(); + } else { + System.out.println("Helaas...\n"); + questions_2.add(q.duplicate()); + } + } + } + + private void round2() { + Scanner sc = new Scanner(System.in); + + if (!questions_2.isEmpty()) { + System.out.println("Je krijgt een herkansing voor de " + questions_2.size() + " vragen die je zojuist fout had.\n"); + + for (Question q : questions_2) { + System.out.println(q); + if (q.isCorrect(sc.nextLine())) { + System.out.println("Goed zo!\n"); + score_round2 += q.getWeight(); + } else { + System.out.println("Helaas... het juiste antwoord was: " + q.juisteAntwoord() + "\n"); + } + } + } else { + System.out.println("Alle vragen goed!"); + } } } |