ユーザーが TimeTable を定義できる JTable を実装しています。すべての科目には単位数があり、1 週間ですべての単位数の合計を数えなければなりません。明らかに、そのためには、すべての重複した科目を 1 回カウントする必要があります (同じ科目のクレジットを 2 回カウントすることはありません)。
たとえば、JTable が
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;
}
}
}
しかし、うまくいきません。理由を説明していただけますか?私のコードの正しいバージョンは非常に高く評価されます。