mkv

user

mkv
Aug 6th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. package quiz;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. // Store userdata; name, score, and track question results.
  6. public class User {
  7.    
  8.     // members go on top
  9.     private int score;
  10.     private String username;
  11.     private ArrayList<Question> right, wrong;
  12.    
  13.     // constructors goes right below members
  14.     public User(String username){
  15.         this.username = username;
  16.         right = new ArrayList<Question>();
  17.         wrong = new ArrayList<Question>();
  18.         score = 0;
  19.     }
  20.    
  21.     public String getUsername() {
  22.         return username;
  23.     }
  24.     public int getScore() {
  25.         return score;
  26.     }
  27.     public void increaseScore() {
  28.         score++;
  29.     }
  30.     public ArrayList<Question> getRight() {
  31.         // they SHOULD shout at you for this, since you are exposing a complex private member...
  32.         // instead you should do something like:
  33.         // public Question[] getRight() { return (Question[]) right.toArray();
  34.         // ...except thats too advanced yet so whatever
  35.         return right;
  36.     }
  37.     public ArrayList<Question> getWrong() {
  38.         return wrong;
  39.     }
  40.     public void addRight(Question q) {
  41.         right.add(q);
  42.         score++;
  43.     }
  44.     public void addWrong(Question q) {
  45.         wrong.add(q);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment