Just need a few pointers with the code below.
I have the below class to complete but I am stuck on the isAllValidDigits() method where i have to create a loop to check and return true if all the int values of the authorId array and the programId array are in the valid range of 0-9 inclusive, otherwise return false.

public class ISPN
{
private int[] authorId;
private int[] programId;

/**
* Creates a new instance of ISPN
*/
public ISPN(int[] anAuthorId, int[] aProgramId)
{
int[] authorId = anAuthorId;
int[] programId = aProgramId;
}

public boolean isValidLength()
{
// TODO
int numAuthor = authorId.length;
int numProgram = programId.length;
if((numAuthor + numProgram) == 6)
{
return true;
}
else
{
return false;
}
}

public boolean isAllValidDigits()
{
// TODO
for(int i = 0; i < authorId.length; i++)
for(int j = 0; j < programId.length; j++)
{
if((i >= 0)&&(i <= 9))
{
return true;
}
if((j >= 0)&&(j <= 9))
{
return true;
} 
}
return false;
}
}

Edited 6 Years Ago by Nick Evan: added code tags

public boolean isAllValidDigits()
{
	boolean returnFlag = true;
	for(int i = 0; i < authorId.length; i++){
		if((authorId[i] < 0)||(authorId[i] > 9)){
		// as soon as any number not in the range change the flag and break;
		returnFlag=false;
		break;
		}
	}
	/// no need to chk if flag is false
	if(returnFlag)
	for(int i = 0; i < programId.length; i++){
		if((programId[i] < 0)||(programId[i] > 9))
		{
		returnFlag=false;
		break;
		}
	}
	return returnFlag;
}

Edited 6 Years Ago by Nick Evan: added code tags (again)

Thank you very much vchandra.
That seems to have worked fine.

I have come accross another issue which i can't get my head round it.
I have to find a checkValueNumber based on a calculation.
Then i will have to convert that into a String. If that checkValueNumber is below 9 i need to add a 0 before it to show as 09 instead.
Here's my code below.
Would appreciate any pointers.

thanks

public String toString()
   {
      // TODO
       String value;
       if(calculateCheckValue() > 10)
       {
           value = "0"+ calculateCheckValue();
       }
       else
       {
           value = Integer.toString(calculateCheckValue());
       }
      return "P-" + getAuthorIdAsString() +"-"+ getProgramIdAsString()+"-"+calculateCheckValue();
   }

Thank you very much vchandra.
That seems to have worked fine.

I have come accross another issue which i can't get my head round it.
I have to find a checkValueNumber based on a calculation.
Then i will have to convert that into a String. If that checkValueNumber is below 9 i need to add a 0 before it to show as 09 instead.
Here's my code below.
Would appreciate any pointers.

thanks

public String toString()
   {
      // TODO
       String value;
       if(calculateCheckValue() > 10)
       {
           value = "0"+ calculateCheckValue();
       }
       else
       {
           value = Integer.toString(calculateCheckValue());
       }
      return "P-" + getAuthorIdAsString() +"-"+ getProgramIdAsString()+"-"+calculateCheckValue();
   }
public String toString()
   {
      // TODO
       String value;
       if(calculateCheckValue() < 10)
       {
           value = "0"+ calculateCheckValue();
       }
       else
       {
           value = Integer.toString(calculateCheckValue());
       }
      return "P-" + getAuthorIdAsString() +"-"+ getProgramIdAsString()+"-"+value
   }
This question has already been answered. Start a new discussion instead.