从自定义对象的ArrayList加载随机索引

时间:2014-08-31 13:12:02

标签: java sorting collections arraylist artificial-intelligence

我正在做我最后的Matric项目而且我被困住了。基本上我的应用程序所做的是为您绘制一份学习计划。我的堂兄给了我几次循环的想法,产生了大约10个学习计划并为他们分配了价值,最高价值是给用户选择的时间表。

我正在尝试生成一个随机表,其中绘制了一些预加载主题的时间表,他们的考试日期和他们的分数(用户获得的百分比),这些都将在以后动态填充。我现在正在测试。

我现在面临的问题是:它只加载第一个主题,而不是设置下一个主题。我试图加入约束,例如可以分配给一个主题的最大时间量,但由于某种原因(可能是错误的代码)它不起作用。

所以需要发生的是需要看看我们在考试日期方面根据主题在另一个主题之前学习多长时间(所以英语比IT更多,例如得分所在的地方)。这从最低百分比反转到更高百分比)。

以下是加权类的代码:

public void dayCounter() {
    days = new ArrayList<Day>();
    // loop through for how many days we have to study
    for(int i = 0; i < nodays; i++) {
        // create new day object to store data in
        DateTime d = startDate.plusDays(i);
        // create new day with how many hours we have to study that day
        Day day = new Day(2);
        // set the date and time for the new day object
        day.setDateTime(d);
        // get monday - sunday, what day it is
        DateTime.Property dayOfWeek = d.dayOfWeek();
        // set the day of the week (mon - sun) as name of day object
        day.setName(dayOfWeek.getAsText());
        for(int j = 0; j < day.getMaxNumberOfHours(); j++ ) {
            Subject sub = getSubject();
            try {
                if(sub != null && !sub.isAreHoursCompleted()) {
                    ArrayList<Subject> hoursPerDay = null;
                    if(sub.getExamDate().isBefore(day.getDateTime())) {
                        hoursPerDay = new ArrayList<Subject>();    
                        for(int x = 0; x < day.getMaxNumberOfHours(); x++) {
                            hoursPerDay.add(null);
                        }    
                        sub.subjectByHoursAndDays.put(i, hoursPerDay);
                        sub.totalHoursStudied++;
                    }
                    day.setSubject(sub.getName());
                    day.hours.set(j, sub);

                    hoursPerDay.set(j, sub);
                } else {
                    if(sub.isAreHoursCompleted()) {
                        int index = subjectsSortedByDate.indexOf(sub.getName());
                        subjectsSortedByDate.remove(index);
                    }
                }
            } catch(Exception e) {

            }
        }
        days.add(day);
    }
    System.out.println(days.toString());
}

public Subject getSubject() {
    Subject s = null;
    if(rand.nextDouble() > 0.5) {
        // Assuming subjects are sorted by need to study most
        for(int i = 0; i < subjectsSortedByDate.size(); i++) {
            // get the current subject in the list
            Subject subjectToChoose = subjectsSortedByDate.get(i);
            // check if the hours are completed
            if(!subjectToChoose.areHoursCompleted) {
                // if the hours are not completed set the current subject
                s = subjectToChoose;
                // subject is set, so break out of for loop
                break;
            }
        }
    } else {
        // get a random number in the subjects arraylist
        int index = rand.nextInt(subjects.size());
        subjects.set(index, subjects.get(index));
    }
    return s;
}

初始化rand的行是:

rand = new Random((int) System.currentTimeMillis());

另外,我怎样才能确保一旦考试发生,你就不再需要为该科目学习了?

提前致谢! 约什

0 个答案:

没有答案