This is what I currently have:
public Spherocylinder deleteSpherocylinder(String labelIn)
{
Spherocylinder result = null;
int index = 0;
for (int i = 0; i < elements; i++)
{
if (object[i].getLabel().equalsIgnoreCase(labelIn))
{
for (int j = i; j < elements - 1; j++)
{
object[j] = object[j + 1];
}
elements--;
result = object[elements];
break;
}
}
return result;
}
It does what it is supposed to do which is delete(overwrite) a spherocylinder from my array but when I submit my code for a grade this error comes up:
*Method deleteSpherocylinder of class SpherocylinderList: Method did not return the correct deleted spherocylinder.
*Method deleteSpherocylinder of class SpherocylinderList: Method did not return the correct deleted spherocylinder when using different type casing (ex. SmAlL ExAmPle).
I ran my code and It does all of this and runs perfectly with no problem, could anyone please tell me if anything is wrong with my method, any help would be greatly appreciated.
What I have tried:
i tried:
public Spherocylinder deleteSpherocylinder(String labelIn)
{
Spherocylinder result = null;
int index = 0;
for (int i = 0; i < elements; i++)
{
if (object[i].getLabel().equalsIgnoreCase(labelIn))
{
for (int j = i; j < elements - 1; j++)
{
object[j] = object[j + 1];
result = object[j];
}
object[elements - 1] = null;
elements--;
result = object[elements];
break;
}
}
return result;
}
but it returns null instead of the deleted(overwritten) array. So far this code below seems do exactly as I want but the grading software doesn't like it and thats where im confused.
public Spherocylinder deleteSpherocylinder(String labelIn)
{
Spherocylinder result = null;
int index = 0;
for (int i = 0; i < elements; i++)
{
if (object[i].getLabel().equalsIgnoreCase(labelIn))
{
for (int j = i; j < elements - 1; j++)
{
object[j] = object[j + 1];
}
elements--;
result = object[elements];
break;
}
}
return result;
}