Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package quiz;
- import java.util.ArrayList;
- // Store userdata; name, score, and track question results.
- public class User {
- // members go on top
- private int score;
- private String username;
- private ArrayList<Question> right, wrong;
- // constructors goes right below members
- public User(String username){
- this.username = username;
- right = new ArrayList<Question>();
- wrong = new ArrayList<Question>();
- score = 0;
- }
- public String getUsername() {
- return username;
- }
- public int getScore() {
- return score;
- }
- public void increaseScore() {
- score++;
- }
- public ArrayList<Question> getRight() {
- // they SHOULD shout at you for this, since you are exposing a complex private member...
- // instead you should do something like:
- // public Question[] getRight() { return (Question[]) right.toArray();
- // ...except thats too advanced yet so whatever
- return right;
- }
- public ArrayList<Question> getWrong() {
- return wrong;
- }
- public void addRight(Question q) {
- right.add(q);
- score++;
- }
- public void addWrong(Question q) {
- wrong.add(q);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment