Please take a look at this code (with ArrayList implementation)
public String returnCoreUnitsForProgram()
{
ArrayList<String> testArray = new ArrayList<String>();
ProgramClass pc = new ProgramClass("","","","");
if ( pc.getProgramMajor().equals("Software Technology")
|| pc.getProgramMajor().equals("Network Technology" )
|| pc.getProgramMajor().equals("Games Technology" ) )
{
for(int i = 0; i< UnitArray.size() ; i++)
{
if (UnitArray.get(i).getUnitType().equals("Core"))
testArray.add( UnitArray.get(i).getUnitName() );
}
}
return testArray;
}
With ArrayList - I get the error "imcompatible types"
Without ArrayList:
public void returnCoreUnitsForProgram()
{
ProgramClass pc = new ProgramClass("","","","");
if ( pc.getProgramMajor().equals("Software Technology")
|| pc.getProgramMajor().equals("Network Technology" )
|| pc.getProgramMajor().equals("Games Technology" ) )
{
for(int i = 0; i< UnitArray.size() ; i++)
{
if (UnitArray.get(i).getUnitType().equals("Core"))
UnitArray.get(i).getUnitName();
}
}
}
In another class "ProgramClass",
public String programToString()
{
Apps apps = new Apps();
String str = "Program Code: " + getProgramCode()
+"\nProgram Code: " + getProgramName()
+"\nProgram Major: "+ getProgramMajor()
+ apps.returnCoreUnitsForProgram();
return str;
}
I can't possibly do this because returnCoreUnitsForProgram() method is void.
So I'm thinking that my only option is to use the first implementation method with ArrayList.
How can I solve this problem?