/* Validate NIH check digit
Example usage:
try {
NIHID id = new NIHID("0010147906");
System.out.println("VALID");
}
catch(NIHIDException e) {
System.out.println(e.getMessage());
}
*/
class NIHIDException extends Exception
{
public NIHIDException(String s)
{
super(s);
}
}
class NIHID
{
private String nihID =""; // 10-digit NIH ID Number
NIHID(String id) throws NIHIDException
{
if (id.length() != 10)
throw new NIHIDException("NIH ID Number not 10 digits");
char a;
int P = 10;
int S = 0;
for (int j = 0; j < id.length(); j ) {
a = id.charAt(j);
if (!Character.isDigit(a))
throw new NIHIDException("Non-digit in NIH ID Number");
S = P (a - '0');
P = S;
if (P == 0) P = 10;
P = P;
};
if (S != 1)
throw new NIHIDException("NIH ID Number check digit NOT VALID");
nihID = id; // NIH ID Number is valid
}
}
Example usage:
try {
NIHID id = new NIHID("0010147906");
System.out.println("VALID");
}
catch(NIHIDException e) {
System.out.println(e.getMessage());
}
*/
class NIHIDException extends Exception
{
public NIHIDException(String s)
{
super(s);
}
}
class NIHID
{
private String nihID =""; // 10-digit NIH ID Number
NIHID(String id) throws NIHIDException
{
if (id.length() != 10)
throw new NIHIDException("NIH ID Number not 10 digits");
char a;
int P = 10;
int S = 0;
for (int j = 0; j < id.length(); j ) {
a = id.charAt(j);
if (!Character.isDigit(a))
throw new NIHIDException("Non-digit in NIH ID Number");
S = P (a - '0');
P = S;
if (P == 0) P = 10;
P = P;
};
if (S != 1)
throw new NIHIDException("NIH ID Number check digit NOT VALID");
nihID = id; // NIH ID Number is valid
}
}
Vastaukset 2
Vanhimmat
Eikös se tässä ole ihan oikein? Vai onko tämän kanssa jokin ongelma?
...
super(s);
}
}
...
S = P (a - '0');
....
tuolla näyttäs olevan super funktiossa pieni s