Developer Tools
JDeveloper
In the generated Java class, after the method:
public CreditRating() {
super();
}
Add the following method, which accepts and processes an input string value, and then returns an integer value:
public int processRating (String ssn) {
int id;
try
{
// Parses integer value of first 3 numbers form SSN
id = Integer.parseInt(ssn.substring(0, 3));
}
catch (NumberFormatException e)
{
// if SSN is invalid returns -1
return -1;
}
if (id < 300)
{
// If value of the first 3 numbers from customer SSN is less
// than 300, rating is 1.
return 1;
}
else if (id < 600)
{
// If value less than 600, rating is 2.
return 2;
}
else if (id < 900)
{
// If value less than 900, rating is 3.
return 3;
}
else
{
// Otherwise, rating is 0.
return 0;
}
}
Instead of typing the sample code, you can copy the code in this window and then paste it into the source editor.
Copyright © 1997, 2009, Oracle. All rights reserved.