Skip to content
Advertisement

Is there a algorithm to resolve credit rating?

I need to implement a logic in either Java OR SQL for the following.

There are credit ratings from numbers 1 to 11. And corresponding to each rating say x, I have 3 grades, effectively :x+, x and x-. Difference between each grade is termed as a step. For example, 2 and 2- is single(1) step,2+ and 2- is double(2) step, and 2- and 3+ is again a single(1) step.

My objective is to programmatically find out the number of steps between two credit rating values, until the difference in number of steps is 3.

I tried to solve this problem using conditional (if-else/case) statements, but a deeper analysis led to the conclusion that this would require about 50 odd such statements, which is not a very efficient thing to do, at least in terms of code layout.

Is there any other way to get the number of steps? Perhaps using a temporary data structure, and then using that for lookup?

Note: I can have the two credit rating values pulled into Java Code from DB and then compute number of steps. Alternatively, I need to create a database object(like procedure, function) and then have the number of steps computed that way, such that my Java code can directly consume it.

Advertisement

Answer

I would just assign a numeric value to each rating and have a function that subtracts one from the other.

JavaScript
JavaScript
JavaScript

I am not sure whether a PL/SQL function is acceptable though, since you started by saying you wanted to use either Java or SQL.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement