You want it to populate the class and department after hitting tab and entering account? That would need to be a field changed function. My answer will be in 2.0 as i believe all should be coding in that lately.
I believe in context there is an attribute for line. context.line gives you the line number you are on. If line !=0 then you could do getSublistValue () of line -1 and set fieldId to class and call again for department. Then use setCurrentSublistValue () to set the line you are on.
Where you will probably want to add some logic is I am assuming you probably want every 2 lines to match (debit and credit) not necessarily all lines. Without knowing your business, it is hard to best identify how to do this but it is something you should consider.