设置新部分时,我需要跟踪计数器。例如,如果 m1 是黄铜并且我使用 setSection(Strings); 我希望它是 Brass-- 和 Strings++ 但我不确定如何使用 if statments 并且我不确定 getSection()toString() 是否可以让我获得原始部分
/**This function sets a musician's Orchestra Section.
@param section is a SymphonySection indicating the musician's Orchestra Section.*/
public void setSection(SymphonySection section) {
this.section = section;
if (getSection().toString().equals( "Strings" )){
Strings--;
}
else if (getSection().toString().equals( "Brass" )){
Brass--;
}
else if (getSection().toString().equals( "Conductor" )){
Conductor--;
}
else if (getSection().toString().equals( "Percussion" )){
Percussion--;
}
else if (getSection().toString().equals( "WoodWinds" )){
WoodWinds--;
}
if (section.toString().equals( "Strings" )){
Strings++;
}
else if (section.toString().equals( "Brass" )){
Brass ++;
}
else if (section.toString().equals( "Conductor" )){
Conductor ++;
}
else if (section.toString().equals( "Percussion" )){
Percussion ++;
}
else if (section.toString().equals( "WoodWinds" )){
WoodWinds ++;
}
}