0

ユーザーが TimeTable を定義できる JTable を実装しています。すべての科目には単位数があり、1 週間ですべての単位数の合計を数えなければなりません。明らかに、そのためには、すべての重複した科目を 1 回カウントする必要があります (同じ科目のクレジットを 2 回カウントすることはありません)。

たとえば、JTable が TimeTableの例を想像してください

Math値, English, Science,Philosophyを1 回Artだけ取得したいと思います。私はフォロワーメソッドでこれをやろうとしました:

private void getOnce (String[] dailyLessons)
{   
    Set<String> weekSubjects = new HashSet<String>();
    int weeklyCredits=0;

        //dailylessons is a String[] that contains the lessons of the day
    Collections.addAll(weekSubjects, dailyLessons);

    //String[] week would contain every subject only one time
        String [] week = weekSubjects.toArray(new String[0]);

    //for all the subject I get its credits
    for (int i=0; i<week.length; i++)
     {
        if (!week[i].equals("no"))
        {
            String [] credits= week[i].getCredits;
            weeklyCredits += credits;
        }
        }
}

しかし、うまくいきません。理由を説明していただけますか?私のコードの正しいバージョンは非常に高く評価されます。

4

1 に答える 1