@Override
    public void run() {
        while(!finishedRegistration()) {
            try {
                //Preferred courses first and the other courses second
                if(!triedRegisteringForPreferred) {
                    for(int i = 0; i < NUMPREFERREDCOURSES; i++) {
                        register(getPreferredCourses().get(i));
                        Thread.sleep(1000);

                    }
                }
                triedRegisteringForPreferred = true;
                if(!finishedRegistration()) {
                    Course backupCourse = findRandomClass();
                    Random rand = new Random();
                    int randomDecision = rand.nextInt(3);
                    if(randomDecision == 0) {
                        if(!askIfFull(backupCourse)) {
                            Thread.sleep(1000);
                            register(backupCourse);
                        }
                    }
                    else if(randomDecision == 1){
                        register(backupCourse);
                    }
                    else {
                        Course withdrawRandom = findRandomRegisteredOrWaitlistClass();
                        withdraw(withdrawRandom);
                    }
                }
                Thread.sleep(1000);
            }
            catch(InterruptedException e) {
                e.printStackTrace();
            }
        }
        getRegistrar().removeFromAllWaitingLists(this);
    }