Friday, September 6, 2013

Accessing instance variable of a class java

Accessing instance variable of a class java

Premise: I'm a newbie.
I'm developing a java program that creates a school timetable and the user
can choose how many classes should be created, teacher and hours per day,
etc; and my problem is when I have to check whether there are "duplicate"
teacher (i.e. if a teacher has at the same time two different classes). My
program has three classes: Class.java, Day.java and Main.java, none of
them extends another, and none of them is abstract or an interface. This
is the code that is bugging me:
for(int l = 0; l < nClasses.length; l++) {
for(int j = 0; j <= l; j++) {
for(int i = 0; i < nClasses[j].nDays.length; i++) {
for(String s : nClasses[j].nDays[i].profpos.keySet()) {
// Check for duplicate teachers
if(j != l && nClasses[l].nDays[i].profpos.containsKey(s)
&& nClasses[j].nDays[i].profhr.get(s) != 0 &&
nClasses[l].nDays[i].profhr.get(s) != 0 &&
nClasses[j].nDays[i].profpos.get(s) ==
nClasses[l].nDays[i].profpos.get(s)) {
System.out.println("Duplicate teacher " +s +" in the
day " +nClasses[j].days[i] +" at position "
+nClasses[j].nDays[i].profpos.get(s) +" in classes "
+classes[j] +" and " +classes[l]);
}
}
}
}
}
There you can find the complete code of the three classes here:
https://gist.github.com/anonymous/6462953
As you can see, I'm using an array of Class() to get then into another
array of Day() to get finally to the profpos HashMap to check if teachers
are duplicates. So, my question was: is there a better way to access to
those HashMaps?

No comments:

Post a Comment