Q1. How will you go about improving on the following code snippet that calculates the new balance based on the current balance, total debits, and total credits? Note: All amounts need to be positive values.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import java.math.BigDecimal; public class CashCalculatorBasic { public BigDecimal getCalculatedAvailableBalance(BigDecimal currentBalance, BigDecimal totalDebits, BigDecimal totalCredits) { BigDecimal result = currentBalance .subtract(totalDebits) .add(totalCredits); System.out.println("The calculated result is " + result); return result; } public static void main(String[] args) { new CashCalculatorBasic().getCalculatedAvailableBalance( new BigDecimal("1250.00"), new BigDecimal("250.00"), new BigDecimal("500.00")); } } |
A1. Firstly, a good…