aboutsummaryrefslogtreecommitdiff
path: root/Week5 Quiz/src/week5/Question.java
blob: 3b054149a55d90c7a525782e3e4a9b93f449d0f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package week5;

/**
 * Abstract class for quiz questions
 * 
 * @author Camil Staps, s4498062
 */
public abstract class Question {
    
    protected String question = "";
    protected int weight = 3;

    @Override
    public String toString() {
        return question + " (pt: " + weight + ")";
    }
    
    /**
     * Checks if a given answer is correct
     * 
     * @param answer the answer to check
     * @return true iff the answer is correct
     */
    public abstract boolean isCorrect(String answer);
    
    /**
     * Returns the correct answer
     * 
     * @return the correct answer
     */
    public abstract String juisteAntwoord();
    
    /**
     * Set the weight of this question (succeeds only if 0 < weight < 6)
     * 
     * @param weight the new weight
     */
    protected void setWeight(int weight) {
        if (weight > 0 && weight < 6) {
            this.weight = weight;
        }
    }
    
    public int getWeight() {
        return weight;
    }
    
    /**
     * Create a new instance with the same parameters
     * 
     * @return the new question
     */
    public Question duplicate() {
        return this;
    }
}